可用触发器解決(或用日誌性記錄表)create table tb_a([id] int identity(1,1), a1 varchar(10)) go insert tb_a select 'a' union select 'b' --try create trigger t_a on tb_a after insert as if (select count(*) from tb_a where a1 in (select a1 from inserted))>1 begin delete from tb_a where [id] in (select min([id]) from tb_a where a1 in (select a1 from inserted)) end
CSDN搜搜create table tb_a([id] int identity(1,1), a1 varchar(10)) go insert tb_a select 'a' union select 'b' --try create trigger t_a on tb_a after insert as if (select count(*) from tb_a where a1 in (select a1 from inserted))>1 begin delete from tb_a where [id] in (select min([id]) from tb_a where a1 in (select a1 from inserted)) end
go
insert tb_a
select 'a'
union
select 'b'
--try
create trigger t_a on tb_a
after insert
as
if (select count(*) from tb_a where a1 in (select a1 from inserted))>1
begin
delete from tb_a where [id] in (select min([id]) from tb_a where a1 in (select a1 from inserted))
end
go
insert tb_a
select 'a'
union
select 'b'
--try
create trigger t_a on tb_a
after insert
as
if (select count(*) from tb_a where a1 in (select a1 from inserted))>1
begin
delete from tb_a where [id] in (select min([id]) from tb_a where a1 in (select a1 from inserted))
end
是支持触发器的,具体用法可直接参考自带的样例
其实楼上已经贴出来一些了