mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
87b0cc9912
Based on the patch by Sriram Patil, made under terms of GSoC 2014.
37 lines
1.6 KiB
Text
37 lines
1.6 KiB
Text
CREATE DATABASE db1;
|
|
USE db1;
|
|
CREATE TABLE t1 (val INT);
|
|
CREATE TRIGGER IF NOT EXISTS val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val;
|
|
SET @sum=0;
|
|
INSERT INTO t1 VALUES (10), (20), (30);
|
|
SELECT @sum;
|
|
@sum
|
|
60
|
|
CREATE TRIGGER IF NOT EXISTS val_sum_new BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val;
|
|
ERROR 42000: This version of MariaDB doesn't yet support 'multiple triggers with the same action time and event for one table'
|
|
CREATE TRIGGER IF NOT EXISTS val_sum AFTER INSERT ON t1 FOR EACH ROW SET @sum = @sum + 1 + NEW.val;
|
|
Warnings:
|
|
Note 1359 Trigger already exists
|
|
CREATE OR REPLACE TRIGGER IF NOT EXISTS val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + 2 + NEW.val;
|
|
ERROR HY000: Incorrect usage of OR REPLACE and IF NOT EXISTS
|
|
SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
|
ACTION_STATEMENT
|
|
SET @sum = @sum + NEW.val
|
|
CREATE OR REPLACE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + 3 + NEW.val;
|
|
SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
|
ACTION_STATEMENT
|
|
SET @sum = @sum + 3 + NEW.val
|
|
CREATE TRIGGER val_sum BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + 4 + NEW.val;
|
|
ERROR HY000: Trigger already exists
|
|
SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
|
ACTION_STATEMENT
|
|
SET @sum = @sum + 3 + NEW.val
|
|
# Clearing up
|
|
DROP TRIGGER IF EXISTS val_sum;
|
|
SELECT ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME='val_sum';
|
|
ACTION_STATEMENT
|
|
DROP TRIGGER IF EXISTS val_sum;
|
|
Warnings:
|
|
Note 1360 Trigger does not exist
|
|
DROP TABLE t1;
|
|
DROP DATABASE db1;
|