This example achieves the following results:0. The test database has the userinfo user information table and the userinfolog user information log table.1. When a new record is created for a userinfo table, the trigger adds the new log to userinfolog.2. Create a stored procedure for adding records to the userinfo table3. Based on the date of birth field in the userinfo table, we will create a user-defined function for simple age calculation.4. Create a
MySQL trigger Update triggers Insert failure
To display the historical records of tables with status updates only, you need to create a trigger in the original table to write the updated content to another table at the same time.
So the test
-- Create a test tableCreate table 'triggertest _ trigger' ('id' INT (11) not
There are two ways of 1.mysql cascading updates: Trigger updates and foreign key updates.2. Trigger updates and foreign key updates are intended to ensure data integrity.We usually have this requirement: delete the records in Table 1, and you need to delete several records related to table 1 in the other tables.As an example:Existing 2 entities-mahjong machine st
To be ashamed, MySQL has been in a phase that will only be used and not understood. Even some of the more profound management, are not familiar with, have to strengthen AH!Recently, system testing, using MySQL database, need to create a trigger on a table, the database is installed natively. However, you cannot create a trigg
MySQL does not have a client like MSSQL to manage, so with phpMyAdmin, managing MySQL does not rely solely on command lines, but phpMyAdmin does not seem to be so omnipotent and occasionally
MySQL does not have a client like MSSQL to manage, so with phpMyAdmin, managing MySQL does not rely solely on command lines, but
Trigger.
It can be before the event is triggered, or after the world is triggered.
Trigger creation Syntax:
Official definition:
CREATE [DEFINER = { user | CURRENT_USER }] TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW trigger_body
You cannot understand it. Here is an intuitive one:
Create triggerTriggername
After/before inse
the impending operation;We use a typical case to differentiate between them and create a new trigger:#监视地点: Product Table O#监视事件: Insert#触发时间: Before#触发事件: UpdateCase: When a new order record is added, the number of items in the order is judged, if the quantity is greater than 10, the default is changed to 10Create Trigger Tg6Before insert on OFor each rowBeginIf New.much > ten ThenSet New.much = 10;End If
the additions and deletions, we have the opportunity to judge, modify the impending operation;
we use a typical case to differentiate between them, create a new trigger:
#监视地点: Product table o
# Monitor events: Insert
#触发时间: Before
#触发事件: Update
case: When an order record is added, the number of items in the order is determined, if the quantity is greater than 10, the default change is
Trigger Tg
Python full stack road series MySQL TriggerLWhen you want to 增/删/改 trigger a particular behavior before and after a table, triggers are used to customize the behavior of the user 增/删/改 before and after the rows of the table.
To create a trigger basic syntaxBefore insertingCREATE TRIGGER tri_before_insert_tb1 befo
The project for creating a MySQL trigger requires that the self-controlled data be read to the relational database for data display in the portal system. Due to the large amount of data, the data in the table needs to be cleared regularly, therefore, we need to use the MySQL event scheduler. 1. Check whether the event scheduler is enabled; showvariableslike % sch
This article describes the MySQL set trigger permissions method, the situation is very useful for permissions errors. The specific analysis is as follows:
The MySQL import data hint does not have the Super Privilege permission processing, as follows:
ERROR 1419 (HY000): You don't have the SUPER privilege and Binary Logging is Enabled
Import functi
This example describes how to set the trigger permission in MYSQL. The specific analysis is as follows: the mysql DATA import prompt does not have the SUPERPrivilege permission for processing, as shown below: ERROR1419 (HY000): YoudonothavetheSUPERPrivilegeandBinaryLoggingisEnabled import function
This example describes how to set the
Differentiation between after and before for MySQL triggerAfter: add, delete, modify, and then trigger the data. The triggered statement is later than the added, deleted, and modified statement, which cannot affect the previous add, delete, modify, or insert order records first, then update the product quantity. Database explosion occurs when the number of products is less than the order quantity. Before. C
Label:For some time without writing and forgetting. /*Cancel foreign KEY constraint*/
SETForeign_key_checks=0; /*create C1 table primary key ID field name*/
DROP TABLE IF EXISTS' C1 ';CREATE TABLE' C1 ' (' ID ')int( One) not NULLauto_increment, ' name 'varchar( -)CHARACTER SETUtf8mb4DEFAULT NULL,
PRIMARY KEY(' id ')) ENGINE=MEMORYDEFAULTCHARSET=latin1; /*C2 the same as the C1 structure removed the ID self-increment*/
DROP TABLE IF EXISTS' C2 ';CREATE TABLE' C2 ' (' ID ')int( One) not NULL, ' n
Label:~ ~ Grammar ~ ~ CREATE TRIGGER --The trigger must have a name, a maximum of 64 characters, and may be appended with a delimiter. It is basically like naming other objects in MySQL.{before | After} --the trigger has a time setting for execution: it can be set either before or after the event occurs.{INSERT |UPDAT
The following articles mainly introduce MySQL triggers, stored procedures, and examples of functions and views. The following describes the triggers, stored procedures, and specific operation solutions of functions and views, I hope this will help you in your future studies.
Demo of MySQL triggers, stored procedures, and functions and views:
0. The test database has the userinfo user information table and t
How to automatically update Memcache using MySQL triggers
Mysql 5.1 supports triggers and UDF features. if libmemcache and Memcached Functions for MySQL are used together, memcache can be automatically updated. Record the installation and testing steps.
Installation steps
Install memcached. This step is simple and can be seen everywhere. Install
The following is an implementation method. The idea is to find a way to interrupt a trigger by using an incorrect statement.
Code .
Mysql> Create Table t_control (ID int primary key );
Query OK, 0 rows affected (0.11 Sec)
Mysql> insert into t_control values (1 );
Query OK, 1 row affected (0.05 Sec)
Mysql> Create Table
Here is a way to implement it. The idea is to find a way to interrupt the execution of the code by using an error statement in the trigger.
Mysql> CREATE TABLE T_control (ID int primary key);
Query OK, 0 rows affected (0.11 sec)
mysql> INSERT INTO T_control values (1);
Query OK, 1 row affected (0.05 sec)
Mysql> CREATE
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.