What is "Instead of" triggers "?
From Database Log :
What are "Instead of" triggers?
In previous versions of SQL Server, Triggers were sections of code that were pinned to tables and executed automatically after predefined updates occurred to a specified table. They still exist, of course, in SQL Server 2000 and up. Instead of triggers attached to the table in a similar way, but the code inside them is executed instead of the original update.
a source to share
Triggers are primarily used to limit business constraints. Business constraints can be implemented in the following order: Entity integrity (primary / unique key), domain integrity (check constraint), referential integrity (foreign key), and finally triggers. Tergers are used to enforce complex business constraints that are complex.
Triggers are like stored procedures that are automatically executed based on the Data Manipulation action. "Instead of triggers" are used to process data that we want to process ourselves. Instead INSERT
, UPDATE
, DELETE
are recorded in the table for examining the data and take the necessary action themselves.
Eg. If you do not want to DELETE
execute on the table and you want to control the users who try to delete data in the table. We can write INSTEAD OF TRIGGER
and write the information currentuser
to the audit table.
Eg. If you want to send custom messages for user action. In the exam schedule, if a user tries to take an exam on the weekend, we can send a custom message: "This is Weekend.Take Rest"
Eg. If we have a view defined on several tables and an insert is being checked in it, we can instead of a trigger perform the corresponding insert in the underlying tables.