以下查询不会失败,但也不会插入唯一值。
我只想插入唯一值
DECLARE @user_id AS varchar(80)
DECLARE @real_name as varchar(250)
--新的唯一值是“aaa”并且它们不存在于目标表中
SET @user_id = 'aaa'
SET @real_name = 'aaa'
INSERT INTO TargetTable
([user_id],real_name)
SELECT @user_id, @real_name
WHERE NOT EXISTS
(SELECT [user_id],real_name FROM TargetTable)