Yep, I'd just put the limit in the stored procedure. Something like :
DELETE FROM table t WHERE
t.ID not in (SELECT ID from table t2 ORDER BY t2.date DESC LIMIT 1000)
That's pretty much what I've been playing with, Chris and Erich. But I was concerned that two users making entries at the same time might cause problems if two steps were required (one to delete the oldest entry, and one to insert the new one). I probably could get around that by setting the limit higher than the actual number of posts I want to render.
Basically, I'm building a site that will allow literally anyone to post anything they want about a given topic, without logging in. Like an online soapbox in the town square where people can rant freely. The posts will remain until they are replaced by new posts (in other words, the most recent post will replace the oldest post, once the limit is reached). I figure I'll probably use an initial limit of five posts, until the site catches on.
Selecting only the five most recent posts to display is easy. But ideally, I also would like the older posts to be deleted from the database itself when the new ones are posted, not so much to limit the database size (which will be quite small, anyway); but because I want the existence of the posts
anywhere to be ephemeral, so if someone asks what was posted on such-and-such a date, the honest answer will be, "I have no idea."
In effect, I'm trying to simulate a real soapbox in a town square, where things that are said will soon fade into the ether, and will be heard only by those who happened to be there to hear them.
In addition, my lawyer has advised me that whatever liability I might have for making such a soapbox available will be "substantially mitigated by the ephemeral nature of the venue." But just in case someone does show up with a subpoena and wants to know what was posted on such-and-such a date, it would be in the best interests of freedom of expression if the database contained no more then the most current posts.
He likened it to a person who owns a piece of land, such as a courtyard, that is commonly used by anonymous individuals to rant and rave. The owner of the courtyard shouldn't be required to tape-record everything that's said there.
I'll probably use something along the lines of what you posted, but just set the limit to a safe margin above the number of posts I actually want to present on the site, in case two posters happen to click "submit" at the very same moment in time.
As for triggers, I'm running 5.0.91, but I've found the triggers to be a little buggy. I used them to try to auto-prune some databases in the past, and sometimes they wound up locking things up so tight that I had to restart the SQL server (which kind of stinks on a server hosting multiple domains). So I'm a little hesitant to go there again...
Rich