Three examples of mysql triggers

Source: Internet
Author: User

Mysql triggers are an important concept of mysql databases. The following describes three examples of mysql triggers for your reference. It is helpful for you to learn about mysql triggers.

 
 
  1. Example 1
  2. Delimiter //
  3. Create trigger InsertUser
  4. Before insert on user
  5. For each row
  6. Begin
  7. Insert into user_group (uid, gid) values (new. uid, 'group444444444444 ');
  8. End ;//
  9. Delimiter;
  10.  
  11. Example 2
  12. Delimiter //
  13. Create trigger InsertUser
  14. Before insert on user
  15. For each row
  16. Begin
  17. IF new. Type = 2 then
  18. Insert into user_group (uid, gid) values (new. uid, 'group444444444444 ');
  19. Else
  20. Insert into user_group (uid, gid) values (new. uid, 'group55555555555 ')
  21. End if;
  22. End ;//
  23. Delimiter;
  24.  
  25. Example 3:
  26. Delimiter //
  27. Create trigger InsertUser
  28. Before insert on user
  29. For each row
  30. Begin
  31. IF new. type = 1 then
  32. Insert into user_group (uid, gid) values (new. uid, '578d3369633b47bd9c1fe8bf905cbfb1 ');
  33. End if;
  34. IF new. type = 2 then
  35. Insert into user_group (uid, gid) values (new. uid, '387bcd57fc5a4c3c9de83ee210fef661 ');
  36. End if;
  37. End ;//
  38. Delimiter;

How to configure connection to multiple mysql servers

Mysql Aggregate functions

MySQL string case-sensitive Conversion Function

Use of MySQL concat Functions

Implementation of MySql remote connection

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.