Posted on
2007-05-11 16:08礼拜一
阅读(2265)
评论(2)
编辑收藏举报
SQL使用触发器避免记录重复插入
droptable bb createtable bb (id int,name varchar(8)) ---添加记录 insert bb select1,'a' unionallselect2,'b' unionallselect3,'c' unionallselect4,'d' --创建触发器 createtrigger tr1 on bb forinsert as begintran ifexists(select id from bb groupby id havingcount(id)=2 ) begin rollbacktran end else begin committran end --测试 insertinto bb values (5,'d')