mirror of
https://github.com/MariaDB/server.git
synced 2025-01-27 01:04:19 +01:00
49 lines
2 KiB
Text
49 lines
2 KiB
Text
|
include/master-slave.inc
|
||
|
[connection master]
|
||
|
# Part 1 - initial creation
|
||
|
CREATE DATABASE db1;
|
||
|
USE db1;
|
||
|
CREATE TABLE t1 (val INT);
|
||
|
CREATE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val + 1;
|
||
|
SET @sum=0;
|
||
|
INSERT INTO t1 VALUES (10), (20), (30);
|
||
|
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Master FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
||
|
ACTION_STATEMENT_Master
|
||
|
SET @sum = @sum + NEW.val + 1
|
||
|
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Slave FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
||
|
ACTION_STATEMENT_Slave
|
||
|
SET @sum = @sum + NEW.val + 1
|
||
|
# Part 2 - CREATE IF NOT EXISTS (on a existing trigger)
|
||
|
CREATE TRIGGER IF NOT EXISTS val_sum AFTER INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val + 2;
|
||
|
Warnings:
|
||
|
Note 1359 Trigger already exists
|
||
|
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Master FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
||
|
ACTION_STATEMENT_Master
|
||
|
SET @sum = @sum + NEW.val + 1
|
||
|
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Slave FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
||
|
ACTION_STATEMENT_Slave
|
||
|
SET @sum = @sum + NEW.val + 1
|
||
|
# Part 3 - CREATE OR REPLACE (on a existing trigger)
|
||
|
CREATE OR REPLACE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val + 3;
|
||
|
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Master FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
||
|
ACTION_STATEMENT_Master
|
||
|
SET @sum = @sum + NEW.val + 3
|
||
|
SELECT ACTION_STATEMENT AS ACTION_STATEMENT_Slave FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
||
|
ACTION_STATEMENT_Slave
|
||
|
SET @sum = @sum + NEW.val + 3
|
||
|
# Clearing up
|
||
|
DROP TRIGGER val_sum;
|
||
|
DROP TABLE t1;
|
||
|
DROP TRIGGER IF EXISTS val_sum;
|
||
|
Warnings:
|
||
|
Note 1360 Trigger does not exist
|
||
|
DROP TRIGGER random_trigger;
|
||
|
ERROR HY000: Trigger does not exist
|
||
|
DROP DATABASE db1;
|
||
|
DROP TRIGGER IF EXISTS val_sum;
|
||
|
ERROR 3D000: No database selected
|
||
|
# Syncing slave with master
|
||
|
DROP TRIGGER val_sum;
|
||
|
ERROR HY000: Trigger does not exist
|
||
|
include/rpl_end.inc
|