Simple usage of SQL Server triggers

Source: Internet
Author: User

The trigger--it's all my understanding of the trigger.

When you do the INSERT, delete, and so on, do some extra work,

For example, adding new data to the inserted table when it is added

Write an example

Insert into UserInfo (Name) output inserted. Id value (' Zhao Liu ')

He will return the ID of the currently inserted data

For example: INSERT INTO A (name,info) output inserted.id values (' Chen Zhi ', ' Shanxi ')

Explain the syntax of the trigger:

Create trigger trigger name on table name

for (after) | instead of [Insert,update,delete]

As

Begin

SQL script

End

Note that if you use for or after to represent the SQL script in the trigger after the [Insert,update,delete] operation has completed or before, and instead of the action replaces the operation with the SQL script in the trigger.

Specific usage:

Create Trigger Gettable on A

Instead of insert

As

Begin

SELECT * FROM A

End

And there is:

Create Trigger Gettable on A

For insert

As

Begin

SELECT * FROM A

End

Simple usage of SQL Server triggers

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.