sql从开始删除

时间:2010-05-29 14:59:42

标签: mysql

无论如何我可以将表中允许的行数限制为40,然后当添加41st时,表会删除第一行吗?

2 个答案:

答案 0 :(得分:2)

是的,您可以使用触发器执行此操作。您使用什么RDMS?

答案 1 :(得分:1)

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;