Create DML Trigger Example
Customer table
ID | LastName | FirstName | Address | City | Type |
---|---|---|---|---|---|
1 | Harry | Howard | aaa | New York | I |
2 | COMP INC | bbb | Boston | C | |
3 | Linda | Anderson | ccc | Boston | I |
4 | Ronald | Hall | ddd | San Diego | I |
5 | INSURANCE INC | eee | Chicago | C |
CREATE TRIGGER trig_customers
ON customers
AFTER INSERT, UPDATE, DELETE
AS PRINT ('You made one DML operation');
GO
insert into customers(LastName, FirstName, Address, City, Type)
values ('Sarah', 'Adams', 'fff', 'San Francisco', 'I');
Result:
You made one DML operation
(1 row(s) affected)
select * from customers;
ID | LastName | FirstName | Address | City | Type |
---|---|---|---|---|---|
1 | Harry | Howard | aaa | New York | I |
2 | COMP INC | bbb | Boston | C | |
3 | Linda | Anderson | ccc | Boston | I |
4 | Ronald | Hall | ddd | San Diego | I |
5 | INSURANCE INC | eee | Chicago | C | |
6 | Sarah | Adams | fff | San Francisco | I |
See also:
SQL Server ->
Create trigger syntax