Please tell me how to create a trigger for Insert , Update and Delete.
This will be used for logs. Please create a sample for me. Yesterday i created an FOR UPDATE trigger but when i were deleting something from frontend then it was putting the row in FOR UPDATE trigger table.
I started from this reference :
http://www.codeproject.com/Articles/25600/Triggers-SQL-Server
then i jumped to
http://www.dotnet-tricks.com/Tutorial/sqlserver/OJ97170312-Different-Types-of-SQL-Server-Triggers.html
But still im confused using it.
I wish you could give me these solutions in one frame :
Lets take an example of Table Employees , EmployeesAudit
Column in Employees :
ID , Name , Salary , LastUpdateBy
Column in EmployeesAudit :
ID, OldName,NewName,OldSalary,NewSalary,AuditAction,AuditTimeStamp,LastUpdateBy
1- On insert in Employees one row should be inserted in EmployeesAudit having AudtioAction value as 'Record Inserted'.
2- On Update in Employees one row should be inserted in EmployessAudit having oldname value , new name value , lastupdateby and AuditAction value as 'Record Updated'
3- On Delete in Employess one row should be inserted in EmployeesAudit having only ID value and AuditAction value as 'Record Deleted' , rest of the column should be NULL
Please help.