|
|
Triggers are used in situations where you want various additions, deletions, and changes to data to be handled immediately. They are a special type of stored procedure that is not called directly by the user, and it takes effect automatically when the data in the specified table changes, waking up to call the trigger in response to an INSERT, UPDATE, or DELETE statement. The main benefit of triggers is that they can contain complex processing logic using Transact-SQL code. As a result, triggers can support all of the functionality of constraints; however, it is not always the best approach for the given functionality. Triggers can also evaluate the state of a table before and after data modifications and take countermeasures based on the differences.
Since triggers are automatically executed, so when the table operated by sql has an exception, there will be all kinds of unpredictable exceptions, and it is difficult to realize complex business logic processing, so in large application systems generally do not use triggers, but use stored procedures or middleware to unify the processing of data. |
Previous: sql why use stored procedures, what are the advantages?Next article: sql create stored procedure with parameters
|