Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


check constraint opinion?


check constraint opinion?

Author
Message
sqlguy-736318
sqlguy-736318
SSC-Enthusiastic
SSC-Enthusiastic (189 reputation)SSC-Enthusiastic (189 reputation)SSC-Enthusiastic (189 reputation)SSC-Enthusiastic (189 reputation)SSC-Enthusiastic (189 reputation)SSC-Enthusiastic (189 reputation)SSC-Enthusiastic (189 reputation)SSC-Enthusiastic (189 reputation)

Group: General Forum Members
Points: 189 Visits: 447
What's your opinion on check constraints in SS?

Check constraints seem good for enforcing constraints at the table level. Putting validation at other levels does not prevent a user from directly entering invalid data in the database.

However, can check constraints potentially slow the database down or create other issues?
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16512 Visits: 16985
sqlguy-736318 (9/25/2012)
What's your opinion on check constraints in SS?

Check constraints seem good for enforcing constraints at the table level. Putting validation at other levels does not prevent a user from directly entering invalid data in the database.

However, can check constraints potentially slow the database down or create other issues?


I am not 100% sure what you are looking for as an answer but...yes check constraints can potentially slow down the database. In fact, they will slow it down. The more important question is how much. Check constraints are usually really really fast to the point that the performance difference is unnoticeable and even difficult to measure. As a DBA it is your job to ensure the data. If that means that only values in a certain range or something like that then you should use check constraints. This is one of the ways as a DBA you have of ensuring that garbage data does not get in the system. I would never trust the validation outside of the database to be consistent. You just need to be sure that whatever constraint you establish is in line with the data requirements.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8199 Visits: 14367
An alternative to CHECK constraints are Foreign Keys referencing lookup tables. These are useful when you need to validate that a value in a column is within a set and that set may need to be changed periodically. For example if your company ships to customers in the USA and Canada you could have a CHECK constraint on the Country column in your CustomerAddress table that made sure that was the case, however if you think you may someday ship to Mexico you may instead want to create a table named Country, add rows for USA and Canada and reference it using a Foreign Key. The, when you start shipping to Mexico you simply add a row to the Country table and from that opint forward you can add rows to CustomerAddress using the new country code.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search