两个表具有相同的顺序
是否可以有两个具有相同递增顺序的表?
我试图用 ID、NAME、ParentID
创建一棵树,并且必须连接两个表。 如果我有不同的 id,ID - ParentId
的树形方案将不起作用。
Table A Table B
ID | NAME | PID ID | NAME | PID
1 | xpto | 0 1 | xpto | 1
Is possible to have two tables with the same incrementing sequence?
I was trying to do a tree with ID, NAME, ParentID
and i have to join two tables.
If i have different id the tree scheme of ID - ParentId
will not work.
Table A Table B
ID | NAME | PID ID | NAME | PID
1 | xpto | 0 1 | xpto | 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果同时执行两个插入,则可以使用 SEQUENCE.NEXTVAL 插入到第一个表中以获取新 ID,然后使用 SEQUENCE.CURRVAL 插入到第二个表中以重用相同的 ID。
If you are doing both inserts at the same time, you can use SEQUENCE.NEXTVAL for the insert into the first table to get a new ID, and then SEQUENCE.CURRVAL for the insert into the second table to reuse the same ID.
我找到了答案:“序列号是独立于表生成的,因此相同的序列可以用于一个或多个表。”
http://download.oracle.com/docs/cd /B19306_01/server.102/b14200/statements_6015.htm
坦克为您提供帮助。
I found the answer: "Sequence numbers are generated independently of tables, so the same sequence can be used for one or for multiple tables."
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6015.htm
Tanks for your help.
您可以有一个主表,它只是序列 PK/FK,然后有两个子表。在主表中插入一行只是为了获取序列,然后使用该序列作为子表中的 PK。如果子表具有相同的顺序,那么为什么不是一张表呢?
You could have a master table that is nothing but the sequence PK/FK and then have two child tables. Insert a row in the master just to get the sequence and then use that sequence as the PK in the child tables. If the child tables have the same sequence then why is not one table?
示例图片
Sample Image