5.3. DML TRIGGERS
They fire in response to DML (Data Manipulation Language) command events that start with with Insert, Update and Delete. Like insert_table, Update_view and Delete_table.
EXAMPLE: - CREATE TRIGGER trgAfterInsert on Employee_Demo
FOR INSERT
AS
Begin
declare @empid int, @empname varchar (55), @empsal Decimal (10, 2), @audit_action varchar(100);
Select @empid=i.Emp_ID from inserted i;
Select @empname=i.Emp_Name from inserted i;
Select @empsal=i.Emp_Sal from inserted i;
Set @audit_action='Inserted Record -- After Insert Trigger.' ;
Insert into Employee_Demo_Audit (Emp_ID, Emp_Name, Emp_Sal, Audit_Action, Audit_Timestamp)
Values (@empid, @empname, @empsal, @audit_action, getdate());
PRINT 'AFTER INSERT trigger fired.' ;
End
EXECUTION: - insert into Employee_Demo (Emp_Name,Emp_Sal) values ('Shailu', 1000);