O'Reilly logo

Guru's Guide to SQL Server™ Stored Procedures, XML, and HTML, The by Ken Henderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

INSTEAD OF Triggers

As its name suggests, an INSTEAD OF trigger executes instead of a DML operation. This is in contrast to AFTER triggers, which run after an operation has completed, but before the transaction has been committed. INSTEAD OF triggers are handy for updates against views and tables that would otherwise be too complex to handle with anything but a stored procedure.

Here's a simple INSTEAD OF trigger example (Listing 8-8):

Listing 8-8. A simple INSTEAD OF trigger at work.
 USE tempdb GO CREATE TABLE AussieArtists (ArtistId int Identity, LastName varchar(30), FirstName varchar(30) ) GO INSERT AussieArtists VALUES ('Gibb', 'Barry') INSERT AussieArtists VALUES ('Gibb', 'Maurice') INSERT AussieArtists VALUES ('Gibb', 'Robin') INSERT ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required