I have a simple table with the columns:
date - DATETIME
name - varchar(50)
text - varchar(200)
How can I get the row containing the oldest date value to delete just before an 11th row is added, so the number of rows is always 10?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use Triggers
create TRIGGER trigger_name before insert on table_nameFOR EACH ROW
BEGIN
if count > 10 then
delete from table_name
insert into table_name values(id, name , quantity);
END if;
END ;
you can also refer to this link
http://dev.mysql.com/doc/refman/5.0/en/triggers.html