MSSQL Codex two MSSQL Trigger

Source: Internet
Author: User

A trigger is a special kind of stored procedure that triggers some other events when a table is DML, and triggers are typically used on more complex constraints of check constraints, and cannot be invoked actively.

The syntax is as follows:

CREATE TRIGGERtrigger_name on{Table | View }--encryption, after encryption can not be modified, but can be called or deleted, specifically how to decrypt, the internet has a long period of SQL code, you can baidu a bit of SQL stored procedure/trigger decryption[With encryption]{{ {  for |After|INSTEAD of} {[INSERT] [DELETE] [UPDATE] }--specifies that a trigger for an existing type should be added again. With APPEND cannot be used with INSTEAD of triggers. --If you explicitly declare an after trigger, you cannot use the clause. The for and after effects are the same as after-action triggers, instead of an alternative trigger that uses the trigger content as an action--the WITH APPEND is only used when a for is specified for backward compatibility (but not INSTEAD of or after). --If you specify EXTERNAL NAME (that is, the trigger is a CLR trigger), you cannot specify with APPEND. [With APPEND]--Microsoft's explanation for this is that using not for REPLICATION to control constraints, identities, and triggers--in some cases, it is best to treat user activity in a replication topology differently from agent activity. --For example, if a user inserts a row at a subscriber and the insert satisfies a check constraint on the table, the replication agent may not need to enforce the same constraint when inserting the row at the Subscriber. [Not for REPLICATION] as--some of the actions that are done before/after DML or DDL. --But unlike Oracle there is a before, if you want to trigger before the table operation, you need to write the program manually--The idea is to insert information into the  inserted/deleted temporary table when you insert it, and you go there to retrieve the relevant information,--and then the original table data to judge, if there is no such data, you can write some pre-insertion operations[{IF UPDATE (column) [{and | OR} UPDATE (column)][. .. n]| IF(columns_updated () updated_bitmask) Column_bitmask[. .. n]}]sql_statement[. .. n]}}

The basic meaning is this, where triggers on the performance of the impact of some, especially when the data is large, so use caution, if you want to optimize the database, it is best to use some constraints. If there are imperfections, there is a need for the great God to correct them.

EG:

MSSQL Codex two MSSQL Trigger

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.