patternsqlModerate
Purpose of IDs in a User Table Database
Viewed 0 times
useridsdatabasepurposetable
Problem
In a table, such as a user table, where there will only be 1 row with a for any particular user, why have an ID field, let alone as the primary key?
Solution
I'd answer with a question: Why do you need a table for a single row?
Regarding the design of the table, any table should have a primary key. I won't discuss that as it's the baseline of any design book. Regarding the way of designing that primary key, there are two schools of thought:
To what line you adhere, it's only a matter of taste.
Regarding the design of the table, any table should have a primary key. I won't discuss that as it's the baseline of any design book. Regarding the way of designing that primary key, there are two schools of thought:
- one that makes the PK as a separate column, usually self generated, like a GUID or and auto increment INT (in your case a separate uniqueidentifier column);
- one that makes the PK as a column (or set of columns) internal to the table (in your case would be a username or email or SSN, whatever makes that user unique) that uniquely identify a record.
To what line you adhere, it's only a matter of taste.
Context
StackExchange Database Administrators Q#2524, answer score: 11
Revisions (0)
No revisions yet.