MySQL database - triggers - introduction, syntax (create, view, delete)

Table of contents

introduce

grammar

create

Check

delete


introduce

The trigger is a database object related to the table, which refers to the Insert/Update and execute the trigger A collection of SQL statements defined in the server. before (BEFORE) or after (AFTER), trigger Delete/

This feature of triggers can assist applications in ensuring data integrity, logging, data verification and other operations on the database side.

uses the aliases OLD and NEW to refer to the changed record content in the trigger, which is similar to other databases. Currently, triggers only supportrow-level triggering, but do not supportstatement-level triggering.

Trigger type NEW and OLD
INSERT type feeler
NEW Indicates data that will be or has been added
UPDATE type toucher
OLD represents the data before modification , NEW represents the data that will be or has been modified a>
DELETE type tactile device
OLD indicates data that will be or has been deleted

grammar

create

CREATE TRIGGER trigger_name
BEFORE/AFTER INSERT/UPDATE/DELETE
ON tbl_name FOR EACH ROW -- 行级触发器
BEGIN

    trigger_stmt ;

END;

Check

SHOW TRIGGERS ;

delete

DROP TRIGGER [schema_name.]trigger_name ; 
-- 如果没有指定 schema_name,默认为当前数据库 。

Subsequent articles will use several cases to gain a more detailed understanding of triggers.


END


Learn from: Dark Horse Programmer - MySQL Database Course

Guess you like

Origin blog.csdn.net/li13437542099/article/details/134604253