Course Content
SQL SERVER
About Lesson
/*
In SQL server there are 3 types of triggers
1. DML triggers – INSERT , Update, Delete 
1.1 – After triggers : fires after the triggering action. (statements complete execution)
1.2 – Instead of triggers :  fires instead of the triggering action.
 
2. DDL triggers
3. Logon trigger
 
—  a trigger is a special kind of stored procedure or function that automatically executes 
when an action occurs in the database server
 
 
*/
 
CREATE TABLE tblEmpLog
(
Id int identity(1,1) primary key,
LogData nvarchar(1000)
)
 
CREATE TRIGGER trig_tbl_emp_after_insert
ON [dbo].[tblemp]
FOR INSERT
AS
BEGIN
Declare @Id int
Select @Id = ENo from inserted
insert into tblEmpLog
values(‘New employee with Id = ‘ + Cast(@Id as nvarchar(5)) + ‘ is added at 
‘ + cast(Getdate() as nvarchar(20)))
END
 
select * from tblEmpLog;