我有两个表,Contacts 和 Contacts_Detail。我正在将记录导入到 Contacts 表中,并且需要运行 SP 以在 Contacts_Detail 表中为 Contacts 中的每条新记录创建一条记录。Contacts 表中有一个 ID,Contacts_Detail 表中有一个匹配的 ID_D。
我正在使用它将记录插入 Contacts_Detail 但得到“子查询返回超过 1 个值”。错误,我不知道为什么。Contacts 中有多个记录需要在 Contacts_Detail 中有匹配的记录。
Insert into Contacts_Detail (ID_D)
select id from Contacts c
left join Contacts_Detail cd
on c.id = cd.id_d
where id_d is null
我愿意接受更好的方式......谢谢。