Skip to main content
Solved

Check constraints changed, why?

  • August 31, 2021
  • 3 replies
  • 77 views

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:

 

 

 

This topic has been closed for replies.

3 replies

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
  • September 2, 2021

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


  • 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: