【发布时间】:2012-07-10 02:17:51
【问题描述】:
可能重复:
Insert statement that checks for duplicate before insert
我想使用外键 b_id 检查问题日志表中是否存在建筑物 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)
【问题讨论】:
标签: sql database select exists