x
login about faq Site discussion (meta-askssc)

sql constraint Vs triggers

For a particular column if both trigger and constraint are assigned. which one is going fire first and why?

more ▼

asked Jan 12 '10 at 02:13 AM in Default

Nani gravatar image

Nani
232 7 10 12

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

My understanding is that the firing order is as follows:

  1. Instead of trigger
  2. Constraints
  3. After trigger

http://msdn.microsoft.com/en-us/library/aa224775(SQL.80).aspx

more ▼

answered Jan 12 '10 at 03:43 AM

Steinar gravatar image

Steinar
1.7k 3 4 6

ya, its correct. Thank You Steinar.

Jan 12 '10 at 05:26 AM Nani

You are welcome :-)

Jan 12 '10 at 06:05 AM Steinar
(comments are locked)
10|1200 characters needed characters left

You also asked for the reason. An INSTEAD OF trigger has to fire first since it completely replaces the operation. Then constraints are checked (since we now have all the new data in place). Finally, AFTER triggers fire. AFTER triggers are not part of the query plan for the original data modification - a new plan is created for them - so logically they must come last.

more ▼

answered Jan 14 '10 at 02:32 AM

SQL Kiwi gravatar image

SQL Kiwi
1k 1 4

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x916
x99
x19

asked: Jan 12 '10 at 02:13 AM

Seen: 2308 times

Last Updated: Jan 12 '10 at 06:25 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.