SQL Database Concepts Question:
Download Job Interview Questions and Answers PDF
What is Triggers in MS SQL Server?
Answer:
-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!"
-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!"
Download Basic SQL Server Interview Questions And Answers
PDF
Previous Question | Next Question |
Tell me about BuiltinAdministrator? | Explain about SQL Server Login? |