In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares with you is about the use of triggers in the database. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it.
The syntax for creating a database trigger is: [CREATE
< BEFORE | AFTER >In MySQL 5.7, you can use CREATE TRIGGER statements to create triggers.
The syntax format is as follows:
CREATE
< BEFORE | AFTER >ON FOR EACH Row
The syntax is as follows:
1. Trigger name
The name of the trigger, which must have a unique name in the current database. If you want to create it in a particular database, the name should be preceded by the name of the database.
2. INSERT | UPDATE | DELETE
A trigger event that specifies the type of statement that activates the trigger.
3. BEFORE | AFTER
BEFORE and AFTER, when the trigger is triggered, indicates that the trigger is fired before or after the statement that activates it. Use the BEFORE option if you want to verify that the new data meets the criteria; if you want to make several or more changes after the statement that activates the trigger is executed, you usually use the AFTER option.
4. Table name
The table name associated with the trigger, which must be a permanent table and cannot be associated with a temporary table or view. The trigger is activated only when an event is triggered on the table.
The same table cannot have two triggers with the same trigger time and event. For example, for a data table, you cannot have two BEFORE UPDATE triggers at the same time, but you can have one BEFORE UPDATE trigger and one BEFORE INSERT trigger, or one BEFORE UPDATE trigger and one AFTER UPDATE trigger.
5. Trigger body
The trigger action body, which contains the MySQL statement that will be executed when the trigger is activated. If you want to execute multiple statements, you can use BEGIN... END compound statement structure.
6 、 FOR EACH ROW
It generally refers to the row-level trigger, and the action of the trigger is activated for each row affected by the trigger event. For example, when you insert multiple rows of data into a table using an INSERT statement, the trigger performs the corresponding trigger action for each row of data insertion.
The above is the use of triggers in the database, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.