Which is better in performance - CONSTRAINT or TRIGGER over
a column which restricts say an input of particular value
in a column of a table?
Answers were Sorted based on User's Feedback
Answer / jerry joseph
Restricting the input using CONSTRAINT will have better
performance but there is a limit to the types of constraints
which we can provide..
With TRIGGERS you have more flexibility and provide a more
variety restrictions to the input.. for example you can
prevent a normal delete and make it a soft delete by setting
an IsDeleted flag using trigger.. we cant have that kind of
flexibility using Constraints..
Is This Answer Correct ? | 6 Yes | 1 No |
Answer / monal
Constraints gets evaluated before statement can be either
inserted or deleted or updated. While trigger executes
after or at the same time statement is executing. So if you
have to roll back transactio because transaction not
meeting condition there is no overhead when you are using
constraint ,but if you have to roll back transaction and
you have a trigger on that table or column either 1
transaction goes through before rolling back. So basically
trigger consumes more resources.
Is This Answer Correct ? | 7 Yes | 3 No |
Answer / guest
Constraint is better in terms of performance for same
operation. Why??
Is This Answer Correct ? | 0 Yes | 3 No |
What is analysis service repository?
What is a partition function in sql server?
What is the temp table?
How to write a query with a right outer join in ms sql server?
Explain the different types of backups available in sql server? : sql server database administration
Explain the difference between primary keys and foreign keys?
Can two tables share a primary key?
How to transfer an existing table from one schema to another schema in ms sql server?
Suppose you want to implement the many-to-many relationships while designing tables. How would you do it?
How can I know what locks are running on which resource?
What are the database objects? : SQL Server Architecture
What is Inner Join?