Answers

Question and Answer:

  Home  Basic SQL Server

⟩ What is Triggers in MS SQL Server?

-In SQL the Trigger is the procedural code that executed when you INSERT, DELETE or UPDATE data in the table.

-Triggers are useful when you want to perform any automatic actions such as cascading changes through related tables, enforcing column restrictions, comparing the results of data modifications and maintaining the referential integrity of data across a database.

-For example, to prevent the user to delete the any Employee from EmpDetails table, following trigger can be created.

create trigger del_emp

on EmpDetails

for delete

as

begin

rollback transaction

print "You cannot delete any Employee!"

end

-When someone will delete a row from the EmpDetails table, the del_emp trigger cancels the deletion, rolls back the transaction, and prints a message "You cannot delete any Employee!"

 139 views

More Questions for you: