SQL server 触发器 防止插入重复数据

2024-12-17 15:25:44
推荐回答(1个)
回答1:

create trigger tri
on table
for insert
as
declare @s varchar(2)
declare @s1 varchar(2)
select @s=Sno,@s1=Cno from inserted
if
(select count(*) from table where Sno=@a and Cno =@s1)>0
begin
print'已经存在'
rollback transaction
end