Reputation: 477
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?
Upvotes: 0
Views: 156
Reputation: 3695
It’s always good to keep your primary-ID
as 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
Keeping it as an auto-increment identity saves you from all above.
Upvotes: 3