sqlserver表中数据操作

1.在表中任意添加数据,用触发器,如果添加到一定数量,就触发删除的操作,删除最先添加的那条数据。
2.比如表中有小于100条或者等于100条数据,ID是自增的,当数据添加到ID为101条的时候,就自动删除ID为1的那条数据,数据添加到ID为102条的时候,就自动删除ID为2的那条数据,就是保证表中不能大于100条数据,如果超过100条就让他溢出

create trigger test
begin
// 得到总数
decalre countNum int (11);
select count(*) into countNum from tablename ;

if(countNum>100){// 判断条件
// 删除
delete tablename where id=(select id from tablename order by id limit 1);
}
end

参考下下面的资料
https://www.cnblogs.com/yank/p/4193820.html