Trigger Object (SQL-DMO)
The Trigger object exposes the attributes of a single Microsoft® SQL Server™ trigger.
Remarks
SQL Server supports using triggers as a kind of stored procedure. Triggers are executed when a specified data modification, such as an attempt to delete a row, is attempted on the table on which the trigger is defined. With the Trigger object, you can:
- Create a SQL Server trigger on an existing SQL Server table.
- Remove an existing SQL Server trigger from a SQL Server table.
- Generate a Transact-SQL script to use in other tools to re-create an existing SQL Server trigger.
- Change ownership of an existing SQL Server trigger.
The Name property of a Trigger object is a character string. The value of the property identifies a SQL Server trigger by name and must conform to the rules guiding trigger naming. The Name property is required when creating a SQL Server trigger.
To create a trigger on an existing SQL Server table
- Create a Trigger object.
- Set the Name property.
- Set the Text property to contain the Transact-SQL script defining the SQL Server trigger behavior. For more information about trigger scripts, see CREATE TRIGGER.
- Get the Table object referencing the SQL Server table you want from the Tables collection of the appropriate Database object.
- Use the BeginAlter method of the Table object to mark the start of changes to the SQL Server table definition.
- Add the new Trigger object to the Triggers collection of the selected Table object.
- Use the DoAlter method of the Table object to mark the end of changes and create the SQL Server trigger.
Methods
Properties
(c) 1988-98 Microsoft Corporation. All Rights Reserved.