我有一些任務擺在我面前。 (DB2數據庫) 我需要創建一個表,這將是一個子表(這是什麼它在SQL調用?) 我需要它,以便它與我的其他表有一個外鍵約束,所以當父表被修改(記錄刪除)子表也丟失了該記錄。DB2子表無法正常工作 - 創建表
一旦我有了表格,我還需要用另一個表格中的數據填充它(如果有一個簡單的方法可以使用UPDATE
這個)。
如果你能指出我正確的方向,這將有助於很多,因爲我甚至不知道要查找什麼語法。
我已經制定的表格:
create table titleauthors (
au_id char(11),
title_id char(6),
au_ord integer,
royaltyshare decimal(5,2));
我創建該表:
create table titles (
title_id char(6),
title varchar(80),
type varchar(12),
pub_id char(4),
price decimal(9,2),
advance decimal(9,2),
ytd_sales integer,
contract integer,
notes varchar(200),
pubdate date);
我需要的title_id與來自父表的title_id相匹配,並使用ON DELETE從該表中刪除CASCADE語法以刪除該表。
我嘗試:
CREATE TABLE BookTitles (
title_id char(6) NOT NULL CONSTRAINT BookTitles_title_id_pk REFERENCES titleauthors(title_id) ON DELETE CASCADE,
title varchar(80) NOT NULL,
type varchar(12),
pub_id char(4),
price decimal(9,2),
advance decimal(9,2),
ytd_sales integer,
contract integer,
notes varchar(200),
pubdate date)
;