我剛剛開始使用SQL,我有一個指定的操作來執行涉及SQL表的關係模式。對一個不存在的表字段的SQL外鍵
我對如何表示下面一個大疑問: 我已經表「原始」是由下面的SQL表示:
create table Original (
idB char(10) not null unique,
tituloM varchar(255) not null,
primary key (idB, tituloM),
foreign key (idB, tituloM) references Musica on delete cascade on update cascade
);
我現在代表表「實時」是具有以下關係表示: Live(idB; tituloM; data; hora; tituloMO),其中idB
和tituloMO
是「原始」的外鍵。我的疑問是,我們在「原始」表中沒有「tituloMO」。我怎麼能代表這個?目前我的「原始」表如下所示:
create table Live (
idB char(10) not null unique,
tituloM varchar(255) not null,
/* date goes here */
/* time goes here */
tituloMO varchar(255) not null,
primary key (idB, tituloM),
foreign key (idB, tituloM) references Musica on delete cascade on update cascade,
foreign key (idB, data, hora) references Concerto on delete cascade on update cascade,
foreign key (idB, tituloMO)
);
如何正確表示tituloMO
字段?
請不要發佈使用標籤代碼 - 它可以是一個真正的痛苦重新格式化。此外,簽名的「提前致謝」是沒有必要的(除了浪費屏幕房地產) - 這是選擇一個答案和upvoting是。 –
你使用什麼DBMS?你的外鍵看起來像是錯過了父表的字段。這是真的允許在任何DBMS? –
是的,我確實缺少父表的字段。謝謝 –