Sql server 2008 检查表中的值是否不存在于另一个sql表中
我有一个表值参数,其中包含guid作为字段,我想将其值输入到另一个不存在guid的表中 这是最好的方法 我现在做的检查似乎不对Sql server 2008 检查表中的值是否不存在于另一个sql表中,sql-server-2008,tsql,Sql Server 2008,Tsql,我有一个表值参数,其中包含guid作为字段,我想将其值输入到另一个不存在guid的表中 这是最好的方法 我现在做的检查似乎不对 IF NOT EXISTS(SELECT F.FieldKey FROM @Fields F INNER JOIN DomainObjectFields DOF ON F.FieldKey = DOF.UniqueKey) --@Fields is the tvp and DomainObjectFields is the regular table I want t
IF NOT EXISTS(SELECT F.FieldKey FROM @Fields F INNER JOIN DomainObjectFields DOF ON F.FieldKey = DOF.UniqueKey)
--@Fields is the tvp and DomainObjectFields is the regular table I want to add values to
关于我想我自己应该使用一个
左外连接
INSERT INTO DomainObjectFields (UniqueKey)
SELECT F.FieldKey
FROM @Fields F
LEFT OUTER JOIN DomainObjectFields DOF
ON DOF.FieldKey = F.UniqueKey
WHERE DOF.UniqueKey IS NULL
我想我自己应该使用左外连接
INSERT INTO DomainObjectFields (UniqueKey)
SELECT F.FieldKey
FROM @Fields F
LEFT OUTER JOIN DomainObjectFields DOF
ON DOF.FieldKey = F.UniqueKey
WHERE DOF.UniqueKey IS NULL
我想我自己应该使用左外连接
INSERT INTO DomainObjectFields (UniqueKey)
SELECT F.FieldKey
FROM @Fields F
LEFT OUTER JOIN DomainObjectFields DOF
ON DOF.FieldKey = F.UniqueKey
WHERE DOF.UniqueKey IS NULL
我想我自己应该使用左外连接
INSERT INTO DomainObjectFields (UniqueKey)
SELECT F.FieldKey
FROM @Fields F
LEFT OUTER JOIN DomainObjectFields DOF
ON DOF.FieldKey = F.UniqueKey
WHERE DOF.UniqueKey IS NULL