-
Notifications
You must be signed in to change notification settings - Fork 0
/
TRIGGERS.sql
57 lines (46 loc) · 896 Bytes
/
TRIGGERS.sql
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
56
57
use cdmx_subway;
-- creating triggers to save modified date
create trigger update_modified_at
before update
on lines_
for each row
set new.modified_at = now();
--
create trigger update_modified_at_ls
before update
on line_stations
for each row
set new.modified_date = now();
--
create trigger update_modified_at_loc
before update
on locations
for each row
set new.modified_date = now();
--
create trigger update_modified_at_stat
before update
on stations
for each row
set new.modified_at = now();
--
create trigger update_modified_at_trains
before update
on trains
for each row
set new.modified_at = now();
--
delimiter //
create trigger update_driver_status
after update
on drivers
for each row
begin
if new.status = 1 then
insert into active_drivers (driver_id)
values (new.id);
else
delete from active_drivers where driver_id = new.id;
end if;
end; //
delimiter ;