Triggers for SQL Server database

Source: Internet
Author: User

There are two types of triggers in SQL Server database: DDL, DML triggers, system triggers, and table triggers, which are triggers that manipulate database objects, and table triggers are triggers for adding or deleting tables. Here we just say the trigger of the table.

The trigger for a table is also divided into two categories: instead of, after (for), and triggers after the table operation and after the table operation respectively. And both triggers have three trigger conditions: INSERT, delete, update. The basic syntax is:

 create  trigger   Tgr_name  on   table_name  with  encrypion - – encryption trigger (typically not written)  for  --  trigger type (for example: instead of/after/for)  update  --  trigger type (for example: Insert/update/delete)  as  begin  -- transact-sql  end  

A trigger is a special type of stored procedure, but it differs from a stored procedure. Triggers are triggered primarily by an event that is automatically invoked to execute. The stored procedure can be called by the name of the stored procedure. The trigger has two special tables: Insert Table (instered table) and delete table (deleted table). Both of these are logical tables and virtual tables. Two tables are created by the system in memory and are not stored in the database. Both tables are read-only and can only read data and not modify the data. The result of these two tables is always the same as the structure of the table to which the trigger was modified. When the trigger finishes working, the two tables are deleted. The relationship between two tables and trigger conditions:

Insert Table (insered) Deleting a table (delete)
Insertion Action (insert) Insert a table to hold inserted records
Modify Operation (update) Insert table to hold updated records Delete the record before the update is stored in the table
Delete action (delete) Delete old records from deleted table

Triggers for SQL Server database

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.