mysql - 在数据库设计中使用用户名作为主键不好吗?

标签 mysql database-design primary-key unique-key

friend 告诉我的:

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) REFERENCES usertable (userID) in all tables using the userID.

以上说法正确吗?为什么或为什么不?

最佳答案

我认为他是对的(出于错误的原因),因为主键不能改变,但 username 可以改变。所以你应该使用 userid 因为它不会改变。

关于mysql - 在数据库设计中使用用户名作为主键不好吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1825613/

相关文章:

SQL - 表连接,其中第一个表中的主键是第二个表中键的一部分

PHP多行表单,自动化MySQL输入

mysql - 关联三个不同表的三个主键

mysql - 数据库必须是 "perfect"吗?

database - 在 Cassandra 中过滤列

python - 使用具有现有数据库 ID 字段的 Django 问题

mysql - SQL 查找没有标记为默认值的链接记录

php - 查找输入字符串中包含列值的行

php - 检查两次之间的时差?

Hibernate/JPA 2/PostgreSQL - 实体 UUID 作为主键