Sloan's profileGranada Coder, C#, Sql S...PhotosBlogLists Tools Help
    5/6/2009

    One True Lookup Table Discussion

     
    I recently saw an article on the "One True Lookup Table".
     
     
    Code Sample Here (Right-click, Save As works best)
     
    The author makes 2 points.
    //
    In most cases, neither of the above applies, and responsibility for data integrity resides solely in the application code.
    Show me such a database, and I’ll show you some data where the code does not match anything in the lookup table.
    //
     
    Well, I can provide a solution that uses a UDF (user defined function) and a check constraint.
    And the statement "and I’ll show you some data where the code does not match anything in the lookup table" would not be valid if this solution is employed.
    The FK exists to keep integrity.<<(This exists in addtion to the constraint)
    And the check constraint makes sure that you only can apply values of the correct "CodeCategory".
    (Aka, I cannot put in a OrderStatus value into a column wanting a Country or similar).
     
    The solution is Sql Server specific, but the idea is there.
     
    Keep in mind I use this for ~most tables.  I still create a few standalone lookup tables when the cookie cutter does not work.
     
    I am not saying this is the best solution in every scenario.  There is a performance issue with validating the check constraint for every INSERT/UPDATE action.
    But for bulk data inserts (or updates), you can drop the constraint and readd it if that becomes an issue.
     

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://sholliday.spaces.live.com/blog/cns!A68482B9628A842A!569.trak
    Weblogs that reference this entry
    • None