sungpeng Posted May 9, 2009 Share Posted May 9, 2009 Check is it possible to auto delete all rows for table name "chess" when it reach 800 rows. The primary ID will start from "1" again instead of continue add to 801, 802, 803. Can I have the php mysql code? Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 9, 2009 Share Posted May 9, 2009 You could use MySQL triggers for that (MySQL 5.0 or higher) Quote Link to comment Share on other sites More sharing options...
sungpeng Posted May 9, 2009 Author Share Posted May 9, 2009 How? Triggers? I am inside mysql 5 now, no button for "triggers". Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 9, 2009 Share Posted May 9, 2009 As far as I know MySQL does not have any buttons at all. http://dev.mysql.com/doc/refman/5.0/en/triggers.html Quote Link to comment Share on other sites More sharing options...
sungpeng Posted May 9, 2009 Author Share Posted May 9, 2009 Can I have the statement? Is like mysql_query("DELETE FROM table WHERE something...."); rename field ID... Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 9, 2009 Share Posted May 9, 2009 Ok... it seems triggers might be a bit too sophisticated tool for you at this moment. How about php code like this <?php $query = "SELECT COUNT(*) AS rowCount FROM chess"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if ($row['rowCount'] >= 500) { $query = "TRUNCATE TABLE chess"; mysql_query($query); } Note that you need to have DROP privilege for `chess` table to be able to use TRUNCATE. Quote Link to comment Share on other sites More sharing options...
sungpeng Posted May 9, 2009 Author Share Posted May 9, 2009 ok Thank I will explore trigger again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.