The trigger cannot be called using the EXEC command, but is activated when the user executes the Transact-SQL statement. Data Operation Language (DML) trigger in
Run INSERT, UPDATE, and (or) DELETE statements. SQL Server can prevent data modifications that do not comply with strict requirements, because SQL Server
Treat the trigger as a transaction. As the trigger is treated as a transaction, you only need to add a ROLLBACK command to the corresponding position of the Code.
To prevent records from going through the trigger. The ROLLBACK Command forces the database server to stop processing modifications and disallow the current transaction.
Forget that this transaction has occurred. In this sense, the trigger can be understood as a database watchdog.
The INSERT trigger can be used to modify, reject or even accept the records being inserted, or even cascade the operation of modifying other tables in the database.
. When an INSERT statement is used to create a new record in a table, the INSERT trigger is triggered. Once you try to insert
For the new record, SQL Server copies the new record to a table (trigger table) in the database and a special table (insert
Table), the new record exists in both tables: trigger table and insert Table. The records in the inserted Table should be exactly the records in the trigger table.
Same. When you need to cascade the modification results to other tables in the entire database, inserting a table is a very important table.
The DELETE trigger is used to restrict data that can be deleted from the database. After the DELETE trigger is added, SQL Server will be deleted
Records are transferred to a logical table (delete table) in the memory. Therefore, records are not completely removed and can still be referenced in code. This type
It is similar to the recycle bin, but the table to be deleted is automatically cleared after the transaction ends. the recycle bin needs to be cleared manually.
The UPDATE trigger is used to constrain the UPDATE statement published by the user. This type of trigger is used to restrict existing data that can be modified by users.
The UPDATE trigger combines the INSERT and DELETE triggers. If update is used to check the occurrence of a Single Column
. If update can be used not only in the UPDATE trigger, but also in the INSERT trigger.
Use the if update statement, because the DELETE statement does not modify the specific column.