冷融合MSSQL:如何在一次提交中插入具有一个唯一 ID 的多行

ColdFusion amp; MSSQL : how to insert multiple rows with one unique id in one submission(冷融合MSSQL:如何在一次提交中插入具有一个唯一 ID 的多行)
本文介绍了冷融合MSSQL:如何在一次提交中插入具有一个唯一 ID 的多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮助我如何在一次提交中提交多行?

此调查表将显示一组源自桌面技能的技能.教师必须在复选框中检查学生的技能并点击提交.

一个学生可以拥有多个技能.如果他有3个技能,那么一旦老师点击提交按钮,发送到数据库的数据将是3行.(表学生技能)

<cfoutput query="skill"><tr><td>#skill.skillname#</td><td align="center">:</td><td><input type="checkbox" name="skillid" value="skillid" checked="checked"></td></tr></cf输出>

餐桌技巧

+---------+------------+|技能 |技能名 |+---------+------------+|1 |画 |+---------+------------+|2 |阅读 |+---------+------------+|3 |舞蹈 |+---------+------------+

表学生技能

+----------+----------||学生|技能 |+----------+----------+|001 |1 ||001 |2 ||002 |1 ||002 |2 ||002 |3 |+----------+----------+

解决方案

另一种插入多条记录的简单方法是 INSERT .. SELECT.(在发布的链接banyr中也提到了).因为技能 ID 存储在另一个表中,您可以使用 IN 子句对它们进行 SELECT.然后通过简单的查询将这些值直接插入到您的另一个表 studenSkill 中,无需循环.

INSERT INTO studenSkill ( studenId, SkillId )选择 <cfqueryparam value="#form.studentId#" cfsqltype="cf_sql_integer">, 技能标识来自技能技能 ID 在哪里(<cfqueryparam value="#form.skillId#" cfsqltype="cf_sql_integer" list="true">)



<块引用>

 <input type="checkbox" name="skillid" value="skillid" check="checked">

顺便说一句,如果这不是拼写错误,请不要忘记查询列名称周围的 # 符号,即skillid"

 <input type="checkbox" name="skillid" value="#skillid#" checked="checked">

can anyone help me on how to submit multiple rows in one submission?

this survey form will display a set of skill that derived from table skill. the teacher will have to check the students skill's in checkboxes and click submit.

a student can have more than one skill. if he has 3 skills, then the data that is sent into database will be in 3 rows once the teacher click the submit button. (table studentskill)

<cfoutput query="skill">
<tr>
    <td>#skill.skillname#</td>
    <td align="center">:</td>
    <td><input type="checkbox" name="skillid" value="skillid" checked="checked"></td>
</tr>
</cfoutput>

table skill

+---------+------------+
| skillid | skillname  |

+---------+------------+

| 1       | draw       |

+---------+------------+

| 2       | read       |

+---------+------------+

| 3       | dance      |

+---------+------------+

table studentskill

+----------+----------|

|studentid | skillid  |

+----------+----------+
| 001      | 1        |
| 001      | 2        |
| 002      | 1        |
| 002      | 2        |
| 002      | 3        |
+----------+----------+

解决方案

Another simple approach for inserting multiple records is an INSERT .. SELECT. (It is also mentioned in the link banyr posted). Because the skill id's are stored in another table, you can use an IN clause to SELECT them. Then insert those values directly into your other table studenSkill with a simple query, no looping.

INSERT INTO studenSkill ( studenId, skillId )
SELECT <cfqueryparam value="#form.studentId#" cfsqltype="cf_sql_integer">
       , skillId
FROM   skill
WHERE  skillId IN 
       (
       <cfqueryparam value="#form.skillId#" cfsqltype="cf_sql_integer" list="true">
       )



    <input type="checkbox" name="skillid" value="skillid" checked="checked">

BTW, in case that is not a typo, do not forget the # signs around the query column name ie "skillid"

  <input type="checkbox" name="skillid" value="#skillid#" checked="checked">

这篇关于冷融合MSSQL:如何在一次提交中插入具有一个唯一 ID 的多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)