使用额外的合成字段而不是主键来引用表

发布于 2024-10-06 22:22:42 字数 281 浏览 0 评论 0原文

我最近不得不使用一个应用程序,其中大多数表不通过主键相互引用,而是依赖于附加的合成字段。例如,假设有表 Person (id, name, token) 和 Pet (id, name, personToken)。一个人可以养很多只宠物。 Pet.personToken 将是引用 Person.token 的外键。

现在,如果我要创建架构,我只需使用 Person.id 来引用其中的记录。我被告知该应用程序使用“令牌”列是为了更轻松地在不同服务器之间迁移数据。

我的问题是,这是相当常见的事情还是只是奇怪的设计?

I've recently had to work with an application where most tables don't reference each other via primary keys, but rather rely on additional synthetic fields. For example, let's say there are tables Person (id, name, token) and Pet (id, name, personToken). One person can have many pets. Pet.personToken would be a foreign key referencing Person.token.

Now, if I was creating the schema, I would simply use Person.id to reference records in that. I was told the application uses "token" columns for the sake of easier data migration between different servers.

My question is, is this something fairly common or is it simply weird design?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挽心 2024-10-13 22:22:42

我不能说这在整个行业中是否很常见,但我在过去开发的许多应用程序中都看到过同样的事情。

我认为这是一个奇怪的设计,最终被实施是因为系统的初始设计没有考虑到足够的想法。

I can't say if it is common across the industry as a whole, but I have seen the same thing done in a number of applications I've worked on the past.

I think it's a strange design that ends up being put in place because not enough thought has been put into initial designs of the system.

痴情 2024-10-13 22:22:42

这看起来简直就是一个奇怪的设计。

我以前从未见过这样的事情。

这似乎有点过分了,我必须看看索引/外键的实现。也不想看到令牌生成器的实现...

当您说时,我被告知应用程序使用“令牌”列是为了更轻松地在不同服务器之间迁移数据。< /em> 这是为了复制吗?或者只是从测试到开发?

总而言之,这似乎不是我遇到过的最好的设计。

This seems to be simply a weird design.

I have not seen something like this before.

This seems to be overkill, and I would have to see the Index/Foreign key implementations. Also would not like to see the implementation of token generator...

When you say the I was told the application uses "token" columns for the sake of easier data migration between different servers. is this for replication? Or simply from test to development?

All in all, this does not seem like the best design I have come accross.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文