-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnswer5.sql
More file actions
55 lines (46 loc) · 909 Bytes
/
Copy pathAnswer5.sql
File metadata and controls
55 lines (46 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- # create database score;
--
-- use score;
--
-- create table student
-- (
-- id int auto_increment primary key,
-- school_id int,
-- ball bigint
-- );
--
-- create table school
-- (
-- id int auto_increment primary key,
-- ball_sum bigint default 0
-- );
drop trigger if exists myTrigger;
delimiter //
create trigger myTrigger
after insert
on student
for each row
begin
call myProcedure(NEW.school_id);
end //
drop trigger if exists student_update;
delimiter //
create trigger student_update
after update
on student
for each row
begin
call myProcedure(NEW.school_id);
end //
drop procedure myProcedure;
delimiter //
create procedure myProcedure(school_id int)
begin
select SUM(ball)
into @sum1
from student
WHERE student.school_id = school_id;
UPDATE school
SET ball_sum = @sum1
WHERE school.id = school_id;
end //