I wanted to know if adding an auto-increment primary index to each table (along or without any other relationship between keys of other table) a good practice?
Example:
whenever I create any table, I always keep a primary auto-increment key called id. Be it users or posts or comments, or any table. That is the default thing that I do. Then I may add other keys like commentid, postid etc. but ‘id’ always stays.
Is it a bad practice?
It’s always good to keep your
primary-IDas an auto-increment Identity this helps you in many ways like:Maintaining unique primary key integrity throughout the records
Reduce the chances of manual entry errors, such as duplication etc.
Saves work
retrieve the last ID in your code than add 1 to it and then save the record
Keeping it as an auto-increment identity saves you from all above.