Hi Sviau,
Thank you for using MSDN Newsgroup! It's my pleasure to assist you with your issue.
From your description, I understand that you would like to know which is faster/better between
Cascade Delete and T-SQL delete. The performance of both of these deleted mechanisms is
quite good and I believe there is little difference on the performance between them. I
recommend that you apply the one that best suits your specific needs and environment.
Cascade RI Constraints and Stored Procedure (T-SQL deletion) each have benefits that
make them useful in special situations. The primary benefit of Stored Procedures is that they
can contain complex processing logic that uses Transact-SQL code.
Both of them have their own specialties/advantages and limitations:
1. Cascading RI allows you to define the actions taken when you attempt to delete a key to
which an existing foreign keys. It allows the deletion of key values to cascade through the
tables defined to have foreign key relationships that can be traced back to the table on which
the modification was performed.
However, please note that CASCADE RI cannot be specified for any foreign keys or primary
keys that have a timestamp column. Moreover, Cascading actions cannot be specified for a
table that has an INSTEAD OF UPDATE or INSTEAD OF DELETE trigger. After a cascading
action has been defined for a table, an INSTEAD OF UPDATE or INSTEAD OF DELETE
trigger cannot be added to it. It also cannot perform "what if" analysis.
2. Stored Procedure is compiled into a single execution plan, which can dramatically improve
the performance if the execution plan is re-used. It assists in achieving a consistent
implementation of logic across applications. You can use triggers (a special type of stored
procedure that automatically takes effect when the data in a specified table is modified) to
automatically perform the deletion. They work no matter what caused the data modification
Triggers are most useful when the features supported by Cascade RI constraints cannot meet
the functional needs of the application. For example:
(a)FOREIGN KEY constraints can validate a column value only with an exact match to a value
in another column, unless the REFERENCES clause defines a cascading referential action.
(b)A CHECK constraint can validate a column value only against a logical expression or
another column in the same table. If your application requires that a column value be
validated against a column in another table, you must use a trigger.
(c)Constraints can communicate about errors only through standardized system error
messages. If your application requires (or can benefit from) customized messages and more
complex error handling, you must use a trigger.
However, please note that these changes can be executed more efficiently through
cascading referential integrity constraints.
Triggers can disallow or roll back changes that violate referential integrity, thereby canceling
the attempted data modification. Such a trigger takes effect when you change a foreign key
and the new value does not match its primary key.
If constraints exist on the trigger table, they are checked after the INSTEAD OF trigger
execution but prior to the AFTER trigger execution. If the constraints are violated, the
INSTEAD OF trigger actions are rolled back and the AFTER trigger is not executed.
3. Above all, Cascade RI Constraints and Stored Procedure (T-SQL deletion) each have
benefits that make them useful in special situations. The primary benefit of Stored Procedures
is that they can contain complex processing logic that uses Transact-SQL code. Therefore,
Stored Procedures (triggers) can support all of the functionality of constraints; however,
triggers are NOT always the best method for a given feature.
Please let me know if my suggestion helps you resolve the problem. If there is anything more I
can assist you with, please feel free to let me know.
Regards,
Billy Yao
Microsoft Online Partner Support
----------------------------------------------------
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only. Thanks.