gpt4 book ai didi

sql - 如何检查记录是否存在于另一个表中,如果不存在则添加

转载 作者:搜寻专家 更新时间:2023-10-30 21:52:31 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
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)

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com