Alters the definition of a trigger created previously by the CREATE TRIGGER statement. For more information about the parameters used in the ALTER TRIGGER statement, see CREATE TRIGGER.
ALTER TRIGGER trigger_name
ON table
[WITH ENCRYPTION]
{
{FOR { [DELETE] [,] [UPDATE] [,][INSERT] }
[NOT FOR REPLICATION]
AS
sql_statement [...n]
}
|
{FOR { [INSERT] [,] [UPDATE] }
[NOT FOR REPLICATION]
AS
{ IF UPDATE (column)
[{AND | OR} UPDATE (column)]
[...n]
| IF (COLUMNS_UPDATED() {bitwise_operator} updated_bitmask)
{ comparison_operator} column_bitmask [...n]
}
sql_statement [...n]
}
}
Note If a previous trigger definition was created using WITH ENCRYPTION or RECOMPILE, these options are only enabled if they are included in ALTER TRIGGER.
Note If the ALTER TRIGGER statement specifies {INSERT, UPDATE, DELETE} | {INSERT, UPDATE} trigger information different from the original CREATE TRIGGER statement, the ALTER TRIGGER statement overrides the behavior specified in CREATE TRIGGER. For example, if an UPDATE trigger is altered to an INSERT trigger and a different INSERT trigger already exists, then an additional INSERT trigger is created.
UPDATE(column) can be used anywhere inside the body of the trigger.
COLUMNS_UPDATED can be used anywhere inside the body of the trigger.
For more information about ALTER TRIGGER, see Remarks in CREATE TRIGGER.
Note Because Microsoft does not support the addition of user-defined triggers on system tables, it is recommended that no user-defined triggers be created on system tables.
ALTER TRIGGER permissions default to members of the db_owner and db_ddladmin fixed database roles, and to the table owner. These permissions are not transferable.
This example creates a trigger that prints a user-defined message to the client when a user tries to add or change data in the roysched table. Then, the trigger is altered using ALTER TRIGGER to apply the trigger only on INSERT activities. This trigger is helpful because it reminds the user who updates or inserts rows into this table to also notify the book authors and publishers.
USE pubs
GO
CREATE TRIGGER royalty_reminder
ON roysched
WITH ENCRYPTION
FOR INSERT, UPDATE
AS RAISERROR (50009, 16, 10)
-- Now, alter the trigger.
USE pubs
GO
ALTER TRIGGER royalty_reminder
ON roysched
FOR INSERT
AS RAISERROR (50009, 16, 10)
Message 50009 is a user-defined message in sysmessages. For information about creating user-defined messages, see sp_addmessage.
DROP TRIGGER | sp_addmessage |
Using Identifiers | Transactions |
Programming Stored Procedures |