If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > CHECK constraint vs. small table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-09, 00:41
memilanuk memilanuk is offline
Registered User
 
Join Date: Nov 2008
Posts: 27
CHECK constraint vs. small table

Hello,

What are some of the pros & cons of using a field (CHECK) constraint vs. a very small table (holding say, 3-5 values)? I've seen a few examples in books & tutorials where they went either way, but not much explanation as to the benefits one way or the other.

A specific example of what I'm looking at is say I want to have a table that tracks various information about club members. One of the fields would be where they bought their membership at. There are not many options here; one of three stores in town or directly through the club. All it normally gets used for is when we print out reports of membership sales in the last given time period (month, year, etc.) we like to know which place is selling the most and make sure they have sufficient applications, etc. on hand. The choices are not likely to change very often, if at all. One thing we definitely want to be able to do is set up data validation i.e. limit the choices for the data entry person to *only* these fixed options. Is that more readily accomplished using one or the other?

TIA,

Monte
Reply With Quote
  #2 (permalink)  
Old 03-30-09, 05:19
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Check constraints require DDL changes to adjust, tables just data modification.
If you want a list for the user, you have to duplicate your list in the check constraint at the front end.

My rule of thumb - I only use check constraints for formulae validations. Any lists I enforce with foreign keys & tables.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #3 (permalink)  
Old 03-30-09, 05:23
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Changing the values in a table is a data change whereas changing a CHECK constraint is a schema change. If the set of values needs to change at runtime or is expected to change more often than you plan to release schema changes then you should use a table. Otherwise you can consider using a CHECK constraint.

In some cases a CHECK constraint can simplify the schema but it has the disadvantage that the list of values can't easily be queried by an application. That may be a problem for application developers but it depends on requirements.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On