在数据库设计中使用用户名作为主键是不是很糟糕? [英] Is it bad to use user name as primary key in database design?
问题描述
我被朋友告知:
你使用什么独特的键?我希望你
不保存整个用户名
---这将占用太多的表空间!为每个
(唯一)用户名分配一个唯一的用户ID,并保存该用户ID
(应为INTEGER UNSIGNED
auto_increment或BIGINT UNSIGNED
auto_increment)。不要忘记
创建引用
What unique key do you use? I hope you are not saving the entire user name --- this will use up too much table space! Assign an unique userID to each (unique) userNAME and save this userID (should be INTEGER UNSIGNED auto_increment or BIGINT UNSIGNED auto_increment). Don't forget to create a reference
FOREIGN KEY( userID
)参考
usertable
( userID
)在所有表
中使用userID。
FOREIGN KEY (userID
) REFERENCES
usertable
(userID
) in all tables
using the userID.
上述声明是否正确?为什么或为什么不?
Is the above statement correct? Why or why not?
推荐答案
我认为他是对的(因为错误的原因),因为主键不能改变, c $ c> username 可以改变。所以你应该使用 userid
,因为它不会改变。
I think he is right ( for the wrong reason) because primary key cannot change, but username
can change. So you should use userid
because it wouldn't change.
这篇关于在数据库设计中使用用户名作为主键是不是很糟糕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!