2
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
5
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
7
DROP TRIGGER test.t1_bi;
8
DROP TRIGGER test.t2_ai;
9
DROP TRIGGER test.t1_bu;
10
DROP TRIGGER test.t2_au;
11
DROP TRIGGER test.t1_bd;
12
DROP TRIGGER test.t2_ad;
13
DROP TABLE IF EXISTS test.t1;
14
DROP TABLE IF EXISTS test.t2;
15
DROP TABLE IF EXISTS test.t3;
16
CREATE TABLE test.t1 (id MEDIUMINT NOT NULL AUTO_INCREMENT, b1 BIT(8), vc VARCHAR(255), bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, f FLOAT DEFAULT 0, total BIGINT UNSIGNED, y YEAR, t TIMESTAMP,PRIMARY KEY(id));
17
CREATE TABLE test.t2 (id MEDIUMINT NOT NULL AUTO_INCREMENT, b1 BIT(8), vc VARCHAR(255), bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, f FLOAT DEFAULT 0, total BIGINT UNSIGNED, y YEAR, t TIMESTAMP,PRIMARY KEY(id));
18
CREATE TABLE test.t3 (id MEDIUMINT NOT NULL AUTO_INCREMENT, b1 BIT(8), vc VARCHAR(255), bc CHAR(255), d DECIMAL(10,4) DEFAULT 0, f FLOAT DEFAULT 0, total BIGINT UNSIGNED, y YEAR, t TIMESTAMP,PRIMARY KEY(id));
19
CREATE TRIGGER test.t1_bi BEFORE INSERT ON test.t1 FOR EACH ROW UPDATE test.t3 SET b1=1 and y=YEAR(NOW())|
20
CREATE TRIGGER test.t2_ai AFTER INSERT ON test.t2 FOR EACH ROW BEGIN
21
INSERT INTO test.t3 VALUES(NULL,0,'MySQL Replication team rocks!', 'Dark beer in prague is #1',12345.34,12.51,0,1965,NOW());
22
UPDATE test.t3 SET f = ROUND(f);
24
CREATE TRIGGER test.t1_bu BEFORE UPDATE on test.t1 FOR EACH ROW BEGIN
25
UPDATE test.t3 SET y = '2000';
26
INSERT INTO test.t3 VALUES(NULL,1,'Testing MySQL databases before update ', 'Insert should work',621.43, 0105.21,0,1974,NOW());
28
CREATE TRIGGER test.t2_au AFTER UPDATE on test.t2 FOR EACH ROW BEGIN
29
DECLARE done INT DEFAULT 0;
30
DECLARE a DECIMAL(10,4);
32
DECLARE num MEDIUMINT;
33
DECLARE cur1 CURSOR FOR SELECT t2.id, t2.d, t2.f FROM test.t2;
34
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
37
FETCH cur1 INTO num, a, b;
39
UPDATE test.t3 SET total =(a*b) WHERE ID = num;
41
UNTIL done END REPEAT;
44
CREATE TRIGGER test.t1_bd BEFORE DELETE on test.t1 FOR EACH ROW BEGIN
45
DECLARE done INT DEFAULT 0;
47
DECLARE b VARCHAR(255);
49
DECLARE d DECIMAL(10,4);
51
DECLARE f BIGINT UNSIGNED;
54
DECLARE cur1 CURSOR FOR SELECT t1.b1, t1.vc, t1.bc, t1.d, t1.f, t1.total, t1.y, t1.t FROM test.t1;
55
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
58
FETCH cur1 INTO a, b, c, d, e, f, g, h;
60
INSERT INTO test.t3 VALUES(NULL, a, b, c, d, e, f, g, h);
62
UNTIL done END REPEAT;
65
CREATE TRIGGER test.t2_ad AFTER DELETE ON test.t2 FOR EACH ROW
67
INSERT INTO test.t1 VALUES(NULL,1,'Testing MySQL databases is a cool ', 'Must make it bug free for the customer',654321.4321,15.21,0,1965,NOW());
68
INSERT INTO test.t2 VALUES(NULL,0,'Testing MySQL databases is a cool ', 'MySQL Customers ROCK!',654321.4321,1.24521,0,YEAR(NOW()),NOW());
69
UPDATE test.t1 SET b1 = 0 WHERE b1 = 1;
70
INSERT INTO test.t2 VALUES(NULL,1,'This is an after update test.', 'If this works, total will not be zero on the master or slave',1.4321,5.221,0,YEAR(NOW()),NOW());
71
UPDATE test.t2 SET b1 = 0 WHERE b1 = 1;
72
INSERT INTO test.t1 VALUES(NULL,1,'add some more test data test.', 'and hope for the best', 3.321,5.221,0,YEAR(NOW()),NOW());
73
DELETE FROM test.t1 WHERE id = 1;
74
DELETE FROM test.t2 WHERE id = 1;
75
DROP TRIGGER test.t1_bi;
76
DROP TRIGGER test.t2_ai;
77
DROP TRIGGER test.t1_bu;
78
DROP TRIGGER test.t2_au;
79
DROP TRIGGER test.t1_bd;
80
DROP TRIGGER test.t2_ad;
81
DROP TABLE IF EXISTS test.t1;
82
DROP TABLE IF EXISTS test.t2;
83
DROP TABLE IF EXISTS test.t3;