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