Create table dbo.GblModule(ID int constraint IX_GblModule unique) go insert into dbo.GblModule select 1 --OKinsert into dbo.GblModule select 1 --重復出錯
GblModule表中有唯一约束或者是主键 先取消掉再插入值
--这样可以查出重复值是什么: select * from ( select 插入值列表 )t where exists(select 1 from gblmodule where 唯一约束所指的列名=t.唯一约束所指的列名)--这样可以避免插入重复值: insert into gblmodule select * from ( select 插入值列表 )t where not exists(select 1 from gblmodule where 唯一约束所指的列名=t.唯一约束所指的列名)
go
insert into dbo.GblModule select 1 --OKinsert into dbo.GblModule select 1 --重復出錯
select * from
(
select 插入值列表
)t where exists(select 1 from gblmodule where 唯一约束所指的列名=t.唯一约束所指的列名)--这样可以避免插入重复值:
insert into gblmodule select * from
(
select 插入值列表
)t where not exists(select 1 from gblmodule where 唯一约束所指的列名=t.唯一约束所指的列名)