MySql IDs are so messy!

0 Savad Dekrup · October 9, 2014
Hello, I need help. After I delete the ID and insert the new one, it shows like this.

article_id = 1
article_id = 2

//DELETE the article_id
//INSERT a new one

article_id = 1
article_id = 3

How do I fixed this? 

Thanks,
Savaddekrup

Post a Reply

Replies

Oldest  Newest  Rating
0 Eugene Botma · October 9, 2014
If you are using a identity (auto incremented index) there is nothing you can do about it, and for a good reason.

Lets say have a few tables, and a many to 1 relationship for an item. Now, you might have forgotten to create the relationship and constraints in your DB. for example:

category id, category name
1,cat1
2,cat2
3,cat3

article_id,category_id
1,1
2,1
3,2
4,3
5,3


If your constraints are not set up, you will be able to delete cat3 without affecting the articles table. If you add a new category, cat606 to the table, and the ID gets set to 3, the articles in your article table that should be in cat3 are now in cat606 instead. Ofcourse, setting up your foreign keys and constraints correctly will prevent this from happening.
  • 1

SQL & Databases

107,015 followers
About

Everything SQL and Databases related in here!

Links
Moderators
Bucky Roberts Administrator