| Lesson 5
| Creating triggers, part 1
| Understand how to create a trigger.
Creating Triggers in SQL-Server(
Creating triggers with Enterprise Manager
You can create a trigger with either Enterprise Manager or Transact-SQL.
To use the Enterprise Manager to create triggers:
- Right-click the name of the table that the trigger will be assigned to.
- Choose the All Tasks | Manage Triggers menu option.
- Enter the appropriate Transact-SQL statements in the Trigger Properties dialog box, shown below:
A trigger can be fi red for any combination of insert, update, or delete events. Triggers are
created and modifi ed with the standard DDL commands, CREATE, ALTER, and DROP, as follows:
CREATE TRIGGER Schema.TriggerName ON Schema.TableName
AFTER | INSTEAD OF [Insert, Update, (and or) Delete]
AS Trigger Code;
You can also create, view and modify triggers using Management Studio’s Object Explorer, as shown in Figure 4-5.
Although you can use Enterprise Manager to create and modify triggers, you will need to use Transact-SQL statements within Enterprise Manager to specify your options.
Creating triggers with Transact-SQL
To create a trigger with Transact-SQL, you will use the
CREATE TRIGGER Transact-SQL statement.
The syntax for this statement is shown in the following SlideShow:
In the next lesson, you will learn how to create triggers that satisfy unique business rules.