Day 19

Quiz

1:What can triggers be used to enforce?
A1: A trigger can be used to enforce the following in a database: data integrity, referential integrity, and business rules. In addition, triggers can be used to maintain derived columns, logs, and audit trails.
2:How many levels of nested triggers are allowed?
A2: You can nest triggers up to a maximum of 32.
3:What happens when a statement in a trigger fails?
A3: Whenever a statement in a trigger fails, the transaction that caused the trigger to fire will be rolled back.

Exercise

1:Using the Northwind database, create a trigger that prevents you from adding a new product without having a valid supplier.
A1:
 Create Trigger tr_Prod_Supplier On Products For Insert As If (Select Count(*) From Inserted ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.