Lesson 11
SQL-Server2016 Trigger Conclusion
This module discused how to use triggers to enforce the business rules that govern your database. Remember that triggers can lose their value, or even be harmful if they are not modified or deleted to accommodate business rule changes.
You will find that many businesses change their business rules often to adapt to changing conditions. Be prepared to customize your database triggers as well, to keep up with these changes.
Having completed this module, you should be able to:
- Describe and define triggers
- Enforce business rules
- Create triggers
- Modify triggers
- Delete triggers
- Test triggers
Glossary terms
This module introduced you to the following terms:
- Business rule
- Cascade
- Event
- Fire
- Nesting
- Trigger
Trigger Summary
SQL Server triggers are special stored procedures attached to table events and cannot be executed
directly, but fi re only in response to an INSERT, UPDATE, or DELETE event on a table.
Users can’t bypass a trigger; and unless the trigger sends a message to the client, the end
user is unaware of its actions.
Developing well-behaved triggers involves understanding transaction fl ow, locking, T-SQL, and
stored procedures. Triggers have a few unique elements that require careful planning, but they provide
execution of complex business rules and data validation.
Trigger Basics
SQL Server triggers fire once per data-modification operation, not once per affected row. This may
seem to be a limitation, but developing set-based triggers actually helps ensure clean logic and fast
performance.
Triggers may be created for the three data-modification commands:
- INSERT,
- UPDATE, and
- DELETE.
For data integrity, sometimes a trigger is the best solution, but be aware of the potential performance impact.
You should consider having business rules enforced by application code instead and only use triggers when this is not feasible.
In the next module, you will learn about SQL Server stored procedures.
SQL Triggers - Quiz
Before moving on to the next module, click the Quiz link below to check your knowledge of the material covered in this module with a short, multiple-choice quiz.
SQL Triggers - Quiz