Mysql trigger newold _ MySQL

Source: Internet
Author: User
Mysql trigger newold details bitsCN.com

Mysql trigger new old

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.

Create trigger tr1

Before update on t22

FOR EACH ROW

BEGIN

SET @ old = OLD. s1;

SET @ new = NEW. s1;

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:

Create table (

Id int primary key auto_increment, # set to auto increment

Name varchar (10)

);

Set the initial value to 1000:

Alter table tablename AUTO_INCREMENT = 1000;

BitsCN.com

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.