create table tb(id int,startday varchar(10),zhouqi int,finishday varchar(10)) go insert into tb select 1,'2008-04-23',1,null insert into tb select 2,'2008-04-23',7,null insert into tb select 3,'2008-04-24',10,null insert into tb select 4,'2008-04-22',9,null insert into tb select 5,'2008-04-23',1,null insert into tb select 6,'2008-04-23',7,null insert into tb select 7,'2008-04-24',10,null insert into tb select 8,'2008-04-22',9,null go select * from tb; gocreate trigger triggername on tb for insert as begin if ((select count(1) from tb ) >= 10) delete a from tb a where exists(select top 5 * from tb where a.id = id) end goinsert into tb select 9,'2008-04-23',1,null insert into tb select 10,'2008-04-23',7,null insert into tb select 11,'2008-04-24',10,null insert into tb select 12,'2008-04-22',9,null insert into tb select 9,'2008-04-23',1,null insert into tb select 10,'2008-04-23',7,null insert into tb select 11,'2008-04-24',10,null insert into tb select 12,'2008-04-22',9,null select * from tb; godrop table tb
create table tb(id int,startday varchar(10),zhouqi int,finishday varchar(10))
go
insert into tb select 1,'2008-04-23',1,null
insert into tb select 2,'2008-04-23',7,null
insert into tb select 3,'2008-04-24',10,null
insert into tb select 4,'2008-04-22',9,null
insert into tb select 5,'2008-04-23',1,null
insert into tb select 6,'2008-04-23',7,null
insert into tb select 7,'2008-04-24',10,null
insert into tb select 8,'2008-04-22',9,null
go
select * from tb;
gocreate trigger triggername
on tb
for insert
as
begin
if ((select count(1) from tb ) >= 10)
delete a from tb a where exists(select top 5 * from tb where a.id = id)
end
goinsert into tb select 9,'2008-04-23',1,null
insert into tb select 10,'2008-04-23',7,null
insert into tb select 11,'2008-04-24',10,null
insert into tb select 12,'2008-04-22',9,null
insert into tb select 9,'2008-04-23',1,null
insert into tb select 10,'2008-04-23',7,null
insert into tb select 11,'2008-04-24',10,null
insert into tb select 12,'2008-04-22',9,null
select * from tb;
godrop table tb