即使用户名是唯一的,仍创建UserID? [英] Create UserID even though usernames unique?

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

问题描述

我的web应用程序将有各种类型的用户:root用户,系统管理员,客户,承包商等。我想有一个表用户,将有用户名,密码 ,以及角色,角色是前述角色之一。例如,我将有一个名为客户的表来存储客户特定的属性。

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.

这里是我的问题。由于所有用户名都是唯一的,我可以使用用户名作为用户表的主键。但是,创建一个用户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.

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

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