-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger.sql
More file actions
68 lines (44 loc) · 908 Bytes
/
Copy pathtrigger.sql
File metadata and controls
68 lines (44 loc) · 908 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
56
57
58
59
60
61
62
63
64
65
66
67
68
-- For a insert
DELIMITER $$
CREATE TRIGGER `before_insert` BEFORE INSERT ON `products` FOR EACH ROW
BEGIN
INSERT INTO history
SET meth = 'INSERT',
id_prod = new.id,
image = new.image,
name = new.name,
price = new.price,
comments = new.comments;
END
$$
DELIMITER ;
-- For a delete
DELIMITER $$
CREATE TRIGGER `after_delete` AFTER DELETE ON `products`
FOR EACH ROW
BEGIN
INSERT INTO history
SET meth = 'DELETE',
id_prod = old.id,
image = old.image,
name = old.name,
price = old.price,
comments = old.comments;
END
$$
DELIMITER ;
-- For an update
DELIMITER $$
CREATE TRIGGER `after_edit` AFTER UPDATE ON `products`
FOR EACH ROW
BEGIN
INSERT INTO history
SET meth = 'UPDATE',
id_prod = old.id,
image = old.image,
name = old.name,
price = old.price,
comments = old.comments;
END
$$
DELIMITER ;