以一对多关系插入命令

时间:2020-07-11 08:23:18

标签: sql sql-insert

https://stackoverflow.com/a/1764901/13670488

根据链接中的解决方案,用户可以同时插入3个问题及其答案吗?怎么样?

1 个答案:

答案 0 :(得分:0)

insert将占用多行。例如。

-- Person 10 answered survey 5.
-- Question 1 they picked Offered Answer 3
-- Question 2 they picked Offered Answer 6
-- Question 3 they picked Offered Answer 7
insert into answer (SurveyID, QuestionID, OfferedAnswerID, PersonID)
  values (5, 1, 3, 10), (5, 2, 6, 10), (5, 3, 7, 10);