CREATE TABLE item (
iid INT,
title VARCHAR2(50),
CONSTRAINT pk_iid PRIMARY KEY (iid)
);
CREATE TABLE news (
nid INT,
title VARCHAR2(50),
pubdate DATE,
content LONG,
iid INT,
CONSTRAINT pk_nid PRIMARY KEY (nid),
CONSTRAINT fk_iid FOREIGN KEY (iid) REFERENCES item (iid)
ON DELETE SET NULL
);
-- 测试数据
--create sequence customer_id_seq increment by 1 start with 1 ;
create or replace
trigger trg_item before insert on item for each row
begin
select CUSTOMER_ID_SEQ.nextval into :new. iid from dual;
end;
/
create or replace
trigger trg_news before insert on news for each row
begin
select CUSTOMER_ID_SEQ.nextval into :new.nid from dual;
end;
/
INSERT INTO item (title) VALUES ('aaa'); INSERT INTO item (title) VALUES ('体育新闻'); INSERT INTO item (title) VALUES ('娱乐新闻'); INSERT INTO item (title) VALUES ('财经新闻'); INSERT INTO item (title) VALUES ('科技新闻');