Solved

Check constraints changed, why?

  • 31 August 2021
  • 3 replies
  • 63 views

Userlevel 5
Badge +20

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')

 

icon

Best answer by Erwin Ekkel 3 September 2021, 09:12

View original

3 replies

Userlevel 6
Badge +16

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.

Userlevel 5
Badge +20

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

Userlevel 6
Badge +16

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:

 

 

 

Reply