MySQL
  Home arrow MySQL arrow Page 3 - Database Design Using Key-Value Tables
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Database Design Using Key-Value Tables
By: Tal Olier
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 25
    2006-02-13

    Table of Contents:
  • Database Design Using Key-Value Tables
  • Traditional database design vs. key-value table
  • Drawback no. 1: No real use of database data types
  • Drawback no. 2: Awkward use of database constraints
  • Drawback no. 3: Problematic use of AND operator when relating to more than one attribute in the query criteria

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database Design Using Key-Value Tables - Drawback no. 1: No real use of database data types


    (Page 3 of 5 )

    When designing a database table, in most cases the design includes exact data types. This is important because the use of correct data types can help enforce data integrity.

    In our EMPLOYEES example, the VALUE1 column is able to contain any value that is less than or equal to 100 charters length.

    Consider the following sql statement:

    UPDATE EMPLOYEE_ATTRIBUTES SET VALUE1 = 'AAA' WHERE EMPLOYEE_ID = 1 AND KEY1 = 'START_WORK_YEAR';

    This statement will execute without success and the result would be as follows:

    EMPLOYEE_ATTRIBUTES

    EMPLOYEE_ID

    ATTRIBUTE_ID

    KEY

    VALUE

    1

    2

    START_WORK_YEAR

    AAA

    Of course, having our data describing that employee no. 1 (Dany) has started working on date ‘AAA’ is indeed a data integrity failure.

    In the case of scenario 1, the equivalent statement would be:

    UPDATE EMPLOYEES SET START_WORK_YEAR = 'AAA';

    This of course will raise a database error saying that the data provided for column START_WORK_YEAR has a data type mismatch.

    Another data type issue would arise when we will need to cast the string VALUE1 to a numeric data type in order to perform some mathematic computations with it.

    These problems can be worked around by defining a column of NUMERIC data type for numeric values and another column of data type VARCHAR for alphanumeric values, but it will never be as good as having the exact data type that matches our data.

    More MySQL Articles
    More By Tal Olier


       · i rated this article 4 out of 5 because it does an excellent job of describing and...
       · This design flaw is called EAV (Entity-Attribute-Value) and it does not work. It...
       · But I have to echo the sentiments listed here. If you do not exercise iron-clad...
       · In my previous comment, I stated that I have NEVER seen meta-data done right. Take...
       · This design is a wonderful thing for holding global data of multiple types or for...
       · Thanks.Did you read it all?I’ve mentioned all drawbacks I know, do you have...
       · Having been a dba over the past 36 years for DB2, Oracle, SAS, MySQL, and a few...
       · There are many systems that work on EAV for recording observations and...
     

       

    MYSQL ARTICLES

    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway