如何在sql中将两个表之间的关系更改为多对多对多关系?我使用oracle数据库。
谢谢
表之间的关系几乎总是一对多或一对一。两个表之间不存在MANY-TWO-MANY关系。如果你想要一个多对多,你需要创建一个中间关系来保存这个关系。
例如,如果想在表 a 和表B之间建立多对多关系,则需要创建一个中间表C:create table a (a_id number primary key);
create table b (b_id number primary key);
-- c will hold many-to-many relationship between a and b
create table c (
a_id number not null references a(a_id),
b_id number not null references b(b_id),
primary key(a_id, b_id)
);