I am having a gender
table as: gender_id | gender_label
gender_id | gender_label
Will it be a bad practice if I remove the gender_id
column, as gender_label
is also unique and can be used as a primary key?
I know surrogate keys should be used wherever possible as they are efficient and fast to search. But will it make any difference for above scenario? How?
I have written hundreds of tables. 2/3 of them have a "natural" key; 1/3 have a "surrogate key".
From that, I deduce that the answer to your question is "it depends".
OK, so what does it depend on?
UNIQUE
? If so, probably you should use it. country_code
taken from an international standard is, in my opinion, better than a 4-byte INT
. In your simple case, is gender_id
strings like M/F/etc? That's what I would use. Actually, I might not have the table at all; instead have gender
in other tables as ENUM('unknown', 'male', 'female', 'other')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.