Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql auto increment primary key id's

I have some mysql tables that have auto incrementing id's that are primary keys, but I notice that I never actually use them... I used to think that every table must have a primary key so I guess that is why I created them before. Should I remove them all if I don't use them at all?

like image 539
Roger Avatar asked Oct 23 '09 23:10

Roger


1 Answers

Unless you are running into space problems I wouldn't remove them.

They are a life saver in case you by mistake (or oversight) populate the database with repeated/wrong data.

They also help to have related tables, where you reference the content on one table through the autogenerated id.

This is assuming you have indexes for the other columns you use to actually query the data (if you don't, then more reason to keep the autoincrement ids and use them!).

like image 85
Vinko Vrsalovic Avatar answered Sep 18 '22 03:09

Vinko Vrsalovic