In Previous Article we seen types of Triggers in SQL Server , now in this article we will know steps for how to create DML triggers on a table.In this example we are creating trigger for employee table
1. After triggers or For triggers:
Step 1: Create a sample table employee Like below screen
Step 3: If We try to insert data into employee table on Sundays the trigger fires automatically and it won’t allow data into employee table.
Step 4: employee table accepts data except Sundays. Like system date is not Sunday employee accept data please follow below screen
Step 5: Create a trigger on employee table for restrict if we try to update join_date is Sunday. Please follow below screen.
Step 6: If We try to update join_date is Sunday in employee table then trigger fires automatically and it won’t update data if join_date is Sunday.
Step 7 : Create sample table for storing deleted records for maintain history for deleted records.
Step 8: Create a trigger on employee table if we delete records in employee table these records automatically insert into deleted_history table. Please follow below screen
Step 9: Before delete operation on employee table we have records in employee and deleted_history table.Please follow below screen.
Step 10: Perform delete operation on employee table.
Step 11: After delete operation on employee table we have records in employee and deleted_history table.Please follow below screen
2.Instead of triggers
Create a instead of trigger on employee table for restrict DML operation.Please follow below screen
Did you find this post as useful? I hope you liked the article. Please share your valuable suggestions and feedback in the comments.