Introduction to mysql trigger new old

Source: Internet
Author: User

Next we will introduce you to the mysql trigger new old for your reference. If you have encountered similar problems in mysql trigger, you may wish to take a look and I believe it will help you.

Mysql trigger new old:

"NEW. column_name" or "OLD. column_name". Technically, NEW | OLD. column_name) and OLD

The column name belongs to the created transition variable "transition variables ").

For INSERT statements, only NEW statements are valid. For DELETE statements, only OLD statements are valid. For UPDATE statements

OLD is used at the same time. The following is an example of using both NEW and OLD in UPDATE.

 
 
  1. CREATE TRIGGER tr1  
  2. BEFORE UPDATE ON t22   
  3. FOR EACH ROW   
  4. BEGIN   
  5. SET @old = OLD.s1;   
  6. SET @new = NEW.s1;   
  7. END; 

If the value of column s1 in Table t21 is 55, the value of @ old is 55 after "UPDATE t21 SET s1 = s1 + 1" is executed,

The value of @ new will change to 56.

Trigger execution interval: The for each row clause notifies the trigger to execute an action on every ROW instead of the entire table.

Increasing column values:

 
 
  1. Create table (
  2. Id int primary key auto_increment, # Set to auto Increment
  3. Name varchar (10)
  4. );

Set the initial value to 1000:
Alter table tablename AUTO_INCREMENT = 1000;
 

Create MySQL trigger syntax

Three examples of mysql triggers

Mysql Aggregate functions

MySQL string connection function repeat ()

Use of MySQL concat Functions

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.