可能重复:
Insert statement that checks for duplicate before insert如何检查是否在另一个表中存在记录,如果没有则添加
我想检查是否在问题日志存在一个建筑ID表使用外键b_id。如果它不存在,那么我想将它添加到问题日志表中。 我有下面的代码,但这只能检查哪些建筑物不在问题日志表中......我该怎么做插入?非常感谢。我使用的是SQL Server 2008的
select b.b_id from building
where not exists(select b.b_id from issue_log as l where b._id = l.b_id)