Override full mysql table

304 Views Asked by At

Recently I stuck with a problem such that mysql table with memory engine got full, and an insertion failed (really really long php script). I quickly got rid of it, by checking before I insert whether there's already many rows and deleting them

if (query("Select count(*) As c From my_table")['c'] > $N)
{
    query("Delete from my_table Order by ID Limit " . round($N/2));
}

But that doesn't feel cool. Actually, I want mysql to do it for me. Now, the question:
is there a standard alternative to AUTO_INCREMENT, but which would return not LAST+1 every time, but LAST+1 (mod N). And which would let to just override lines with old ID column value. Is there such mechanism, or I have to implement it myself?
Thank you.

0

There are 0 best solutions below