Dragen Posted April 13, 2007 Share Posted April 13, 2007 Hi, Is it possible to reset a primary key within a database? I've been using my database to test things and I have a primary key which is now in its thousands when I add things to it, although there is nothing on it at the moment. Can I reset it so that it starts at 1 again? Thanks Link to comment https://forums.phpfreaks.com/topic/46798-solved-resetting-a-primary-key/ Share on other sites More sharing options...
clown[NOR] Posted April 13, 2007 Share Posted April 13, 2007 yeah i want to know that to =) Link to comment https://forums.phpfreaks.com/topic/46798-solved-resetting-a-primary-key/#findComment-228082 Share on other sites More sharing options...
Dragen Posted April 13, 2007 Author Share Posted April 13, 2007 hehe, I saw that you'd replied and thought you'd have a lovely answer to help me like usual Link to comment https://forums.phpfreaks.com/topic/46798-solved-resetting-a-primary-key/#findComment-228083 Share on other sites More sharing options...
clown[NOR] Posted April 13, 2007 Share Posted April 13, 2007 hehe =) do you want to do it manually or trough code? i'm going to check my phpmyadmin now Link to comment https://forums.phpfreaks.com/topic/46798-solved-resetting-a-primary-key/#findComment-228084 Share on other sites More sharing options...
clown[NOR] Posted April 13, 2007 Share Posted April 13, 2007 this might be of interest tho: ALTER TABLE tablename AUTO_INCREMENT = 1 found it here: http://www.liewcf.com/blog/archives/2004/04/mysql-reset-auto-increament-number/ Link to comment https://forums.phpfreaks.com/topic/46798-solved-resetting-a-primary-key/#findComment-228090 Share on other sites More sharing options...
Dragen Posted April 13, 2007 Author Share Posted April 13, 2007 yeah thanks. That's good if you've got stuff on the table that you want to keep. I found that if you use truncate it resets the values of auto primary keys (although deleting everything else on the table), which is fine for what I need as when I reset the primary key I want everything else deleted as well: mysql_query("TRUNCATE table TABLE_NAME"); Link to comment https://forums.phpfreaks.com/topic/46798-solved-resetting-a-primary-key/#findComment-228092 Share on other sites More sharing options...
clown[NOR] Posted April 13, 2007 Share Posted April 13, 2007 ahh ok... oh well... we both just learned something usefull then NOTE: Remember to mark as solved Link to comment https://forums.phpfreaks.com/topic/46798-solved-resetting-a-primary-key/#findComment-228094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.