数据库设计问题:处理 GUID 周围的地方
这是一个简化的示例。
UserDetails (UserID INT UserGUID UNIQUEIDENTIFIER Name VARCHAR(50) Age INT)
UserRatings (UserID INT Rating INT Date DATETIME)
UserVotes (UserID INT Votes INT Date DATETIME)
UserGUID 仅存在于主表中。
在应用程序层中,仅解析 GUID,而不解析 INTS。这是为了防止竞争对手猜测我网站上的一些关键数字(例如用户数)。
在与表 UserRatings 和 UserVotes 相关的 SPROCS 中,我必须声明 UserID 并根据在每个过程开始时解析的 UserGUID 来设置它。
这种情况不仅发生在 Users 表中,而且发生在具有主表和分支表的所有其他对象中,因此到处都有大量这些 DECLARE/SET 类型的过程。
这是一个好的设计吗?
Here's a simplified example.
UserDetails (UserID INT UserGUID UNIQUEIDENTIFIER Name VARCHAR(50) Age INT)
UserRatings (UserID INT Rating INT Date DATETIME)
UserVotes (UserID INT Votes INT Date DATETIME)
The UserGUID only exists in the main table.
In the application layer only GUID's are parsed around, never INTS. This is to prevent competitors from guessing at some key numbers on my site like (e.g. user count).
In the SPROCS relating to tables UserRatings and UserVotes, I have to DECLARE UserID and SET it based on the UserGUID that is getting parsed back at the start of every procedure.
This occurs not just for the Users table but for every other object that has a main table and branched tables so there are tons of these DECLARE/SET type procedures all over the place.
Is this a good design?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将删除 uniqueidentifier UserGUID 列并仅使用普通的 int UserID。如果您想让 ID 随机化以进行混淆/混淆,那么只需删除身份并使用一些函数/过程,在每次插入新用户时随机生成一个值在 1 到 2,147,483,647 之间的普通 int。
I would remove the uniqueidentifier UserGUID column and just use a the plain int UserID. If you want to make the IDs random to confuse/obfuscate, then just remove the identity and use some function/procedure that randomly generates a plain int with a value between 1 and 2,147,483,647 every time you INSERT a new user.
对我来说似乎很合理。
您还可以定义一个涵盖
UserDetails+UserRatings
以及UserDetails+UserVotes
(甚至同时包含所有三个表)的视图,其中包括来自UserDetails
表。这将使查询表变得更加容易,并且您不必首先从 GUID 中提取 ID 并使用它来查询相关表。更新:例如,如果您需要频繁查询
UserRatings
,您可以创建一个如下所示的视图:然后您可以从该视图中进行选择,而无需运行单独的
SELECT< /code> 首先:
使用正确的索引(在
UserRatings
中的外键字段上),这是一个非常高性能的 JOIN - 不用担心!Seems quite reasonable to me.
You could also define a view spanning
UserDetails+UserRatings
, as well asUserDetails+UserVotes
(or even all three tables at once), which include the GUID from theUserDetails
table. This would make querying the tables easier and you wouldn't have to first extract the ID from the GUID and use that to query the table in question.Update: if you e.g. need to query
UserRatings
frequently, you could create a view like this:and then you can select from that view without running a separate
SELECT
first:With the right indices (on the foreign key field in
UserRatings
), this is a very highly performant JOIN - no worries here!