[Niuyun Video] SQL trigger and niuyun SQL trigger
I learned about the data center management system. I have already written about database operations in the net version, but now I am learning about it, only to find that I have understood it too easily. Many things seem to be okay, this article will summarize how to create an SQL trigger from the beginning to the end instead of the Code. The following uses sql2008r2 as an example:
Step 1: Create a trigger
Find the table where you want to create the trigger-New trigger.
Step 2: Fill in the required information
After you click Create trigger, some initialization Code created for the database will appear, as follows:
What we need to write is to start with create trigger. For example, we need to delete table B after Table A is deleted, assume that the auto-increment id of the AB table is the same, the statement is as follows:
Create trigger trigADelete (TRIGGER name, you can write it yourself) on a (Table A is operated) after delete (AFTER Table A is deleted) ASBEGIINdelete B where id = (select id from A where statement for deleting Table A information) END
Other statements, such as search and addition, are similar. After the statements are compiled, run them once, and our triggers are successfully created.
The creation of a trigger is so simple. However, if you do not do anything simple, it will eventually become difficult! So, if you want to learn something, you can do it to gain more benefits!