Skip to main content
Solved

Check constraints changed, why?


Harm Horstman
Superhero
Forum|alt.badge.img+21

Previous versions, without quotes:

ALTER TABLE dbo.[voyage_completeness_check_period] ADD CONSTRAINT [c_voyage_completeness_check_period_reservation_month] CHECK ([reservation_month]>=1 AND [reservation_month]<=12)

New version, with quotes while the datatype is integer:

ALTER TABLE dbo.[voyage_completeness_check_period] ADD CONSTRAINT [c_voyage_completeness_check_period_reservation_month] CHECK ([reservation_month]>='1' AND [reservation_month]<='12')

 

Best answer by Erwin Ekkel

The execution plan for a table with quoted check constraints compare to a table with non-quoted check constraints is identical. Also the check constraint is translated to integer so it has the same result as without the quotes:

table with quoted check constraint:

 

table with un-quoted check constraint:

 

 

 

View original
Did this topic help you find an answer to your question?
This topic has been closed for replies.

3 replies

Forum|alt.badge.img+17
  • Moderator
  • 768 replies
  • September 2, 2021

This was changed to support constraints based on date. This poses no problem for integers since the check constraint is still treated as integer values.


Harm Horstman
Superhero
Forum|alt.badge.img+21
  • Author
  • Superhero
  • 499 replies
  • September 2, 2021

Ok, not a big problem, but, don’t you think this could cause a decrease in performance?


Forum|alt.badge.img+17
  • Moderator
  • 768 replies
  • Answer
  • September 3, 2021

The execution plan for a table with quoted check constraints compare to a table with non-quoted check constraints is identical. Also the check constraint is translated to integer so it has the same result as without the quotes:

table with quoted check constraint:

 

table with un-quoted check constraint:

 

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings