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')