Book Image

SQL Server 2014 Development Essentials

By : Basit A. Masood-Al-Farooq
Book Image

SQL Server 2014 Development Essentials

By: Basit A. Masood-Al-Farooq

Overview of this book

Table of Contents (14 chapters)
SQL Server 2014 Development Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Creating and using triggers


A trigger is a special type of stored procedure that fires (executes) in response to an event. We typically use triggers to maintain data integrity rules that are too complicated to implement through constraints and referential integrity. We also use triggers to:

  • Implement referential actions, such as cascading deletes

  • Maintain an audit trail of changes

  • Perform administrative tasks such as auditing and regulating database operations

  • Compare data before and after modification

  • Implement custom error messages

Triggers cannot support parameters and should not return values or result sets.

Microsoft SQL Server 2014 has two basic trigger types: DML triggers and DDL triggers.

Note

You can write DDL and DML triggers as Transact-SQL or CLR triggers. In this topic, we will use Transact-SQL to write DDL and DML triggers. For more information about CLR triggers, see CLR triggers at http://msdn.microsoft.com/en-us/library/ms131093.aspx.

Nested triggers

SQL Server 2014 allows the nesting...