一对多表设置
我有一张表,我必须在其中将主键组相互关联。除了这些团体的存在之外,没有任何关于这些团体的信息。具体来说,我将多组书籍的版本存储在一起,这样我就可以知道一组特定的书籍是彼此的版本。
我目前有一个设置,其中有一个 Edition_Group_ISBN 列,其中任意选择一个 ISBN 将一组版本分组在一起。
解决此问题的典型方法是使用一个单独的表,例如 Book_Editions,其中我将有一个自动递增整数主键,例如将 ISBN 连接在一起的“Edition_Group_ID”。有人告诉我这种方法更好。
然而,实现该系统的问题涉及数据的加载。如何动态加载版本组?一种解决方案可能是锁定表并在自动增量中的下一个 ID 上执行事务。不过,我想这会比我目前的方法更慢、更麻烦。
鉴于在该系统下插入数据的困难,解决该问题的最佳系统是什么?
I have a table where I have to relate groups of primary keys to one another. There is no information about these groups other than that they exist. Specifically, I am storing groups of Editions of Books together, so I can know that a certain set of books are editions of each other.
I currently have a setup where I have an Edition_Group_ISBN column, where one of the ISBN's is arbitrarily chosen to group a set of Editions together.
The typical approach for this problem is to have a separate table like Book_Editions, where I would have an autoincrementing integer primary key like "Edition_Group_ID" linking ISBNs together. I have been told this method is preferable.
However, the problem with implementing that system relates to the loading in of data. How am I to dynamically load in Edition Groups? One solution might be to lock the table and do a transaction on the next ID in the autoincrement. I imagine this would be slower and more cumbersome than my current method, though.
Given the difficulty of inserting data under that system, what is the optimal system to address this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在版本组表中使用 ISBN 表外键来加载版本组,然后使用 ISBN 图书表的主键和版本组表的外键在查询中将两个表内连接在一起在加入中。
大多数数据库系统都有一种方法返回新插入记录的主键 ID,因此:
You load in Edition Groups by having an ISBN table foreign key in your Edition Groups table, and then inner-joining your two tables together in your query, using the Primary Key of your ISBN Books table, and the Foreign Key of your Edition Groups table in the join.
Most database systems have a way to return the Primary Key ID of a newly inserted record, so: