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 ...

Get Guru's Guide to SQL Server™ Stored Procedures, XML, and HTML, The 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.