![](/img/trans.png)
[英]How to select from a table in SQL where element in a column contains only one feature of another column which in turn contains two features in itself?
[英]Is it a good practice to use surrogate primary key even if the table contains only one column and that itself contains the unique values?
我的gender
表為: gender_id | gender_label
gender_id | gender_label
如果我刪除了gender_id
列,這是一個不好的做法,因為gender_label
也是唯一的並且可以用作主鍵?
我知道應該盡可能使用代理鍵,因為它們高效且快速地搜索。 但這對上述情況有什么影響嗎? 怎么樣?
我寫了幾百張桌子。 其中2/3具有“自然”鍵; 1/3有一個“代理鑰匙”。
由此,我推斷出您問題的答案是“取決於”。
好的,那取決於什么?
UNIQUE
鑰匙? 如果是這樣, 可能您應該使用它。 country_code
優於4字節的INT
。 在您的簡單情況下,是否像M / F / etc這樣的gender_id
字符串? 那就是我會用的。 實際上,我可能根本沒有桌子。 而是在其他表格中使用gender
作為ENUM('unknown', 'male', 'female', 'other')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.