说我有这些表:
CREATE TABLE person
(
person_id INT NOT NULL PRIMARY KEY,
name VARCHAR NOT NULL,
phone INT,
);
CREATE TABLE volunteers
(
person_id INT NOT NULL PRIMARY KEY,
skill VARCHAR,
FOREIGN KEY (person_id) REFERENCES person(person_id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
当我在volunteers
表中插入新记录时,是否可以在person
上创建可插入volunteers
表的触发器。
像这样:
INSERT INTO volunteers (person_id, name, skill)
VALUES (12345, 'abc xyz', 'cooking');
如果没有使用触发器,还有其他选择吗?
答案 0 :(得分:1)
我不会为您编写代码,但您可以执行以下操作:
instead of
触发器以更新视图视图如下:
create view v_volunteers as
select v.person_id, p.name, v.skill
from volunteers v join
people p
on p.person_id = v.person_id;