How to: Create a Trigger
You can write triggers in Transact-SQL for Microsoft® SQL Server™ databases or PL/SQL for Oracle databases. You create a trigger by specifying:
The current table or view (in the case of INSTEAD OF triggers).
The data modification transactions that activate the trigger; adding new data (INSERT), updating existing data (UPDATE), or deleting existing data (DELETE).
The actions that the trigger will take immediately following the transactions you specify.
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see.
To create a trigger
In Server Explorer, expand the Tables folder.
Right-click the name of the table or view that you want to create a trigger on.
Choose Add New Trigger on the shortcut menu.
A new trigger is created in the source code editor with skeleton SQL statements:
CREATE TRIGGER authors_Trigger1 ON dbo.authors FOR /* INSERT, UPDATE, DELETE */ AS /* IF UPDATE (column_name) . . .*/
CREATE TRIGGER titleview_Trigger1 ON dbo.titleview INSTEAD OF /* INSERT, UPDATE, DELETE */ AS /* IF UPDATE (column_name) . . .*/
Modify the default trigger text as follows:
The name you want to assign to the trigger
/*INSERT, UPDATE, DELETE */
The type of actions that will activate this trigger
/*IF UPDATE (column_name) . . .*/
The transactions that will take place
Write the remaining trigger text in SQL.