T-SQL Tutorial

T-SQL Create DML Trigger


Create DML Trigger Example

Customer table

IDLastNameFirstNameAddressCityType
1HarryHowardaaaNew YorkI
2COMP INCbbbBostonC
3LindaAndersoncccBostonI
4RonaldHalldddSan DiegoI
5INSURANCE INCeeeChicagoC


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;

IDLastNameFirstNameAddressCityType
1HarryHowardaaaNew YorkI
2COMP INCbbbBostonC
3LindaAndersoncccBostonI
4RonaldHalldddSan DiegoI
5INSURANCE INCeeeChicagoC
6SarahAdamsfffSan FranciscoI

See also:
SQL Server -> Create trigger syntax