您的位置:首页 > 数据库

SQL使用触发器避免记录重复插入

2008-11-07 15:46 309 查看
drop table bb

create table bb (id int,name varchar(8))

---添加记录

insert bb select 1,'a'

union all select 2,'b'

union all select 3,'c'

union all select 4,'d'

--创建触发器

create trigger tr1

on bb

for insert

as

begin tran

if exists(select id from bb group by id having count(id)=2 )

begin

rollback tran

end

else

begin

commit tran

end

--测试

insert into bb values (5,'d')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: