即使用户名唯一,也要创建用户 ID? [英] Create UserID even though usernames unique?

查看:31
本文介绍了即使用户名唯一,也要创建用户 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Web 应用程序将有各种类型的用户:root 用户、系统管理员、客户、承包商等.我想要一个包含用户名"、密码"列的用户"表,以及角色",其中角色是上述角色之一.例如,我还会有一个名为Customer"的表,用于存储客户特定的属性.

My web application will have various types of users: a root user, sys-admins, customers, contractors, etc. I'd like to have a table "User" that will have the columns "Username", "Password", and "Role" with role being one of the aforementioned roles. I will, for example, also have a table called "Customer" for storing customer-specific attributes.

这是我的问题.由于所有用户名都是唯一的,我可以使用用户名作为 User 表的主键.但是,创建一个用户 ID"列并使用它而不是用户名列作为 PK 是否更有意义?还有很多其他的表会使用这个用户 PK 作为外键,我认为,从性能的角度来看,比较用户 ID 而不是用户名文本字符串会更快.

Here's my question. Since all usernames will be unique, I could use the username as the primary key for the User table. Would it make more sense, though, to create a "User ID" column and use it rather than the Username column as the PK? There are many other tables that will use this User PK as a foreign key and I would think that, from a performance standpoint, it will be faster to compare user IDs rather than username text strings.

感谢您的回复.

推荐答案

我会创建 userid 因为虽然用户名可能是唯一的,但它们通常不是不可更改的,而且我不想更改数千或数百万条记录,因为 HLGEM想成为 HLGEM_1.进一步连接整数更快.

I would create the userid because while usernames might be unique, they are not generally unchangeable and I would prefer not to have to change thousands or millions of records because HLGEM wanted to become HLGEM_1. Further joins on integers are faster.

这篇关于即使用户名唯一,也要创建用户 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆