Create, modify, and delete mysql triggers.

Source: Internet
Author: User

Create, modify, and delete mysql triggers.

// Make a simple exercise. When creating a simple trigger to add an article, the time is automatically added. By default, the author is 'memories of the records'

 

Show columns from test; // view the table structure

 

// View the existing trigger

Show triggers \ G

// Replace the ending character with $

\ D $

// Create a trigger, use before to insert the trigger (also apply to update), and apply it to each row of the test table, with the unix Timestamp

Create trigger insert_arc before insert on test
For each row
Begin
If new. nickname is null then
Set new. nickname = 'memories of the records ';
End if;
If new. addtime is null then
Set new. addtime = unix_timestamp ();
End if;
End
$

// Insert Test Data

Insert into test () values () $

// Select * from test $

 

 

 

// Perform a simple exercise. When creating a simple trigger to add an article, the time is automatically added. By default, the author sets the 'note In the records' show columns from test; // view the table structure // view the existing trigger show triggers \ G // Replace the Terminator with $ \ d $ // create a trigger, use before to insert a trigger (also for update) and apply it to each row in the test table, time unix timestamp create trigger insert_arc before insert on testfor each rowbegin if new. nickname is null then set new. nickname = 'memory of the records'; end if; if new. addtime is null then set new. addtime = unix_timestamp (); end if; end $ // Insert test data insert into test () values () $ // select * from test $ complete !!!

 

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.