Database Design and the use of non-numeric Primary Keys
There are 2 reasons I would always add an ID number to a lookup / ENUM table:
- If you are referencing a single column table with the name then you may be better served by using a constraint
- What happens if you wanted to rename one of the client_status entries? e.g. if you wanted to change the name from 'affiliate' to 'affiliate user' you would need to update the client table which should not be necessary. The ID number serves as the reference and the name is the description.
In the website table, if you are confident that the name will be unique then it is fine to use as a primary key. Personally I would still assign a numeric ID as it reduces the space used in foreign key tables and I find it easier to manage.
EDIT: As stated above, you will run into problems if the website name is renamed. By making this the primary key you will be making it very difficult if not impossible for this to be changed at a later date.
When making natural PRIMARY KEY
's, make sure their uniqueness is under your control.
If you're absolutely sure you will never ever have uniqueness violation, then it's OK to use these values as PRIMARY KEY
's.
Since website_status
and client_status
seem to be generated and used by you and only by you, it's acceptable to use them as a PRIMARY KEY
, though having a long key may impact performance.
website
name seems be under control of the outer world, that's why I'd make it a plain field. What if they want to rename their website
?
The counterexamples would be SSN
and ZIP
codes: it's not you who generates them and there is no guarantee that they won't be ever duplicated.