Welcome to Day 16 of my “A Month of PowerShell” series. This series will use the series landing page on this blog at //blog.waynesheffield.com/wayne/a-month-of-powershell/. Please refer to this page to see all of the posts in this series, and to quickly go to them.

The last several days we’ve been dealing with tables. Today, we’re going to end up this mini-series of tables by talking about triggers. Today will also start the next mini-series of working with objects that are compiled T-SQL code.

Creating a Trigger

To create a trigger that fires on an update or delete against a table:

Yeah, that’s right… just rollback any updates or deletes against a table. Not a very useful trigger… but it does show you how to make one in PowerShell.

Altering a trigger

Let’s update this trigger so that it only fires if updating or deleting more than five records.

Dropping a trigger

And since this really is a completely useless trigger to have in the database (but it does work out pretty good for showing how to work with triggers in PowerShell), let’s drop it.