立即学习:https://edu.csdn.net/course/play/4364/77170?utm_source=blogtoedu
create table g
(
pid int primary key auto_increment,
pname varchar(20),
pnum int,
price decimal
)
create table o
(
oid int primary key auto_increment,
pid int,
much int
)
insert into g(pname, pnum, price)
values
('毛笔', 100, 5),
('宣纸', 100, 1),
('墨水’, 100, 10)
create TRIGGER tug
AFTER insert on o
for each row
begin
update g set pnum=pnum-NEW.much where pid=NEW.pid
end
insert into o (pid, much) values (1, 20)