SQL Server Database Triggers

SQL Server Database Triggers

1h 39mAdvanced2020-08-25

Authors

Adam Wilbert

Adam Wilbert

Data Visualization Expert

Course details

SQL Server database triggers help database developers automate routine tasks. Triggers wait for an activating event to occur, then immediately respond with preprogrammed operations. This course, from database expert Adam Wilbert, takes a deep dive into leveraging these powerful and flexible components of a SQL Server database. Follow along and learn how to create and deploy different types of triggers, and get hands-on experience using triggers to solve common problems, such as timestamping data changes or collecting information about table events. Adam also helps you manage your database triggers: enabling, disabling, and reordering triggers as necessary. Plus, follow along with a hands-on project in chapter six, which uses triggers to perform tasks automatically in an inventory management system, such as updating inventory when new product is received.

Topics include:
Trigger types
Creating triggers
Firing triggers
Working with modified data
Creating database- and server-level triggers
Enabling and disabling triggers
Reordering trigger execution

Skills covered

SQL ServerData Resource ManagementDatabase AdministrationDatabase ManagementMicrosoftDeep Dive (X:Y)

Concepts

Introduction

  • Automate SQL Server with triggers
  • What you should know
  • Make the most of the exercise files

Trigger Fundamentals

  • What are SQL Server triggers
  • Two triggers types - INSTEAD OF and AFTER
  • Create a trigger to print a message
  • Timestamp a table modification
  • Firing INSTEAD OF triggers
  • Challenge - Create a trigger
  • Solution - Create a trigger

Work with Modified Data

  • Read values modified by a trigger
  • Using the inserted logical table
  • Using the deleted logical table

Database- and Server-Level Triggers

  • Triggers on CREATE, ALTER, or DROP
  • Rollback database modifications
  • Reading the EVENTDATA() XML
  • Writing data from the EVENTDATA() function
  • Challenge - Create a DDL trigger
  • Solution - Create a DDL trigger

Trigger Management

  • View all triggers in a database
  • Enable and disable triggers
  • Disable nested triggers
  • Recursive triggers
  • Reorder trigger execution

Project - Managing Inventory

  • Creating triggers to maintain inventory
  • Counting shipments received
  • Subtract items sold
  • Reorder items when low

Conclusion

  • Next steps
40,000 Toman