Reputation: 75
I am using a varchar random generated string through PHP as the unique identifer at the moment in my tables but after researching on this site, it seems it might be better to use an auto increment primary key field as the unique identifier due to the smaller size integer speed difference plus I wont have to worry about generating the random string.
My friend however has warned about doing this because of the potential for the increment number to change either to 0 if the index is lost or the increment number is reset for any reason. In addition if creating a copy of the database eg. for testing and COPY SELECT is used, the index is not created and the auto increment is lost.
Are these concerns valid? Should I just make the change? :)
Edit 1
I would use the auto increment field as the primary key and use it as the foreign key in other tables so my concern is if for any reason the auto increment primary key in the main table changes then the foreign key in the other tables would become invalid
Upvotes: 0
Views: 183
Reputation: 191729
Just make the change.
auto_increment
must be a primary key. This means that duplicate values are not allowed. Typically you should use int unsigned not null auto_increment primary key
for the definition. No need for negative numbers.INSERT
a value to that column to whatever you want as long as it does not already exist.Upvotes: 1