Mysql triggers are frequently used in the use of mysql trigger databases. The following describes the entire process from creation to use of mysql triggers for your reference.
1. After the latest version is installed, you must run:
Mysql_fix_privilege_tables or mysql_install_db
(You only need to run one of them) -- otherwise, the stored procedure will not work. I also enable an informal SQL script after the root identity, as shown below:
Mysql> source/home/pgulutza/mysql-5.0/scripts/mysql-prepare-privilege-tables-for-5. SQL
2. Verify the version:
Show variables like 'version'; or SELECT version ();
When you see the number '5. 0. x', you can determine that the stored procedure can work properly on this client.
3. Open the database: use database-name
4. Run the delimiter command to change the delimiter before creating a mysql trigger. For example:
Delimiter //
5 | create a mysql trigger
- mysql>create trigger trig1 after insert on test1 for each row
-
- ->BEGIN
-
- ->insert into test2(tvalue) values(NEW.tname);
-
- ->END;
-
- ->//
Here is another example of deletion:
- mysql>create trigger book_trig before delete on lib_book for each row
- ->begin
- ->delete from lib_borrow where book_id=OLD.id;
- ->end;
-
- ->//
6. OK. The trigger is created successfully.
Create MySQL trigger syntax
Three examples of mysql triggers
How to Create a master-slave server for mysql
Mysql Aggregate functions
Use of MySQL concat Functions