You are Here:
FAQ
Scripting & Programming
MSSQL
Article #7
|
TriggersTriggers are result driven procedures which are being triggered when a predefined action (e. g. an update of a certain table) is executed. They can be created as follows: CREATE TRIGGER triggername ON targettable FOR INSERT AS INSERT INTO table (column1) VALUES('value1') This way a trigger called "triggername" will be created, which will run the SQL command "insert into table (column1) values('value')" (which will perform an INSERT on a different table) any time an INSERT is performed on the "targettable" table. A trigger can be removed with DROP TRIGGER triggername A trigger can be modified with ALTER TRIGGER triggername ON targettable FOR INSERT AS INSERT INTO table (column1) VALUES('value1') A listing of all triggers active in the current database (including the corresponding SQL) queries can be performed with the following query: SELECT name, text FROM sysobjects LEFT JOIN syscomments ON sysobjects.id = syscomments.id WHERE type = 'tr' |
© 2007 1&1 Internet Ltd - About 1&1 Internet