In this lesson, you’ll learn what triggers are, why they are used, and how. You’ll also look at the syntax for creating and using them.
T-SQL statements are executed when needed, as are stored procedures. But what if you want a statement (or statements) to be executed automatically when events occur? Here are some examples:
• Every time a customer is added to a database table, check that the phone number is formatted correctly and that the state abbreviation is in uppercase.
• Every time a product is ordered, subtract the ordered quantity from the number in stock.
• Whenever a row is deleted, save a copy in an archive table.
What all these examples have in common ...