Mysql Insert Trigger Notes
INSERT一筆資料前TRIGGER事件
例如將新增的ROW的其中一個FIELD設成AUTO_INCREMENT
CREATE TRIGGER
`priority_trigger`
BEFORE INSERT ON
`banner`
FOR EACH ROW SET
NEW.priority = IFNULL((
SELECT
`AUTO_INCREMENT`
FROM
`information_schema`.`TABLES`
WHERE
`TABLE_SCHEMA` = 'schema'
AND `TABLE_NAME` = 'table'
), 1);
檢視TRIGGERS
SHOW TRIGGERS;
注意:
TRIGGER是平行運行的, 做多行輸入時,
上面的NEW.priority可能會發生一些奇怪問題。