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? Link to comment https://forums.phpfreaks.com/topic/157473-solved-auto-delete-all-rows-for-table-name-chess-when-it-reach-800-rows/ 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) Link to comment https://forums.phpfreaks.com/topic/157473-solved-auto-delete-all-rows-for-table-name-chess-when-it-reach-800-rows/#findComment-830215 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". Link to comment https://forums.phpfreaks.com/topic/157473-solved-auto-delete-all-rows-for-table-name-chess-when-it-reach-800-rows/#findComment-830219 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 Link to comment https://forums.phpfreaks.com/topic/157473-solved-auto-delete-all-rows-for-table-name-chess-when-it-reach-800-rows/#findComment-830222 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... Link to comment https://forums.phpfreaks.com/topic/157473-solved-auto-delete-all-rows-for-table-name-chess-when-it-reach-800-rows/#findComment-830224 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. Link to comment https://forums.phpfreaks.com/topic/157473-solved-auto-delete-all-rows-for-table-name-chess-when-it-reach-800-rows/#findComment-830227 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. Link to comment https://forums.phpfreaks.com/topic/157473-solved-auto-delete-all-rows-for-table-name-chess-when-it-reach-800-rows/#findComment-830238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.