What is "Instead of" triggers "?

Instead Of

Are there triggers in SQL Server ?

+1


a source to share


3 answers


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.

+6


a source


Instead of triggers, it's actually pretty cool. In the past, I have used a read-only view instead of triggers to make it behave like a table.

This is actually pretty cool.



You can even write these triggers in .NET if T-SQL isn't one of your strengths.

+1


a source


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.

0


a source







All Articles