sql从开始删除

问题描述:

是否有无论如何我可以限制在一个表中允许的行数量说40,然后当41st添加时,该表删除第一个?sql从开始删除

+0

您正在使用哪个数据库? (Oracle,MySQL,SQL Server,...) – Andomar 2010-05-29 15:00:18

+0

我正在使用MYSQL – sark9012 2010-05-29 15:02:17

CREATE TABLE animals (
id MEDIUMINT NOT NULL AUTO_INCREMENT, 
name CHAR(30) NOT NULL, 
PRIMARY KEY (id) 
); 

-- if this is 41st record, ... 
-- the statement below will delete the id with 1, and so forth 
insert into animals(name) values('wolverine'); 
delete from animals where id <= LAST_INSERT_ID() - 40; 

是的,你可以用触发器做到这一点。您使用的是什么RDMS?

+0

正在使用MYSQL。 – sark9012 2010-05-29 15:03:13