MySQL
  Home arrow MySQL arrow 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 
Actuate Whitepapers 
VeriSign Whitepapers 
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 / 24
    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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Database Design Using Key-Value Tables


    (Page 1 of 5 )

    In the following article we are going to cover the use of key-value tables in a database design. They can help you with flexibility in design, but will trip you up in other areas (such as data filtering) if you are not careful. I assume that the audience for the following article is familiar with basic traditional relational database design and SQL language; nevertheless, someone that is not familiar with it should be able to comprehend it from the walkthrough example of this article.

    Key-value tables - what is all about?

    Consider the following example table:

     

    CREATE TABLE EMPLOYEES (
    ID          INT               NOT NULL,
    NAME        VARCHAR (10)      NOT NULL,
    SALARY      INT               NOT NULL);

    ALTER TABLE EMPLOYEES ADD CONSTRAINT EMPLOYEES_PK PRIMARY KEY (ID);

    INSERT INTO EMPLOYEES (ID, NAME, SALARY) VALUES (1, 'Dany',
    4000);
    INSERT INTO EMPLOYEES (ID, NAME, SALARY) VALUES (2, 'Brit',
    5000);
    INSERT INTO EMPLOYEES (ID, NAME, SALARY) VALUES (3, 'Sharon',
    1000);

    The above script produces the following table:

    EMPLOYEES

    ID

    NAME

    SALARY

    1

    Dany

    4000

    2

    Brit

    5000

    3

    Sharon

    1000

    This table holds employee description, specifically employee name and salary.

    You might have noticed that there is an additional column called “ID.” We use this column as a primary key, i.e. a unique identifier of each row in the table, which can never be set with a NULL value.

    In a general development process, after collecting the requirements and designing the model, the DBA would create this table, and the programmer would start coding with it.

    In case the requirement changes, we will need to change the table design. For example, what happens if the customer adds a new requirement? We will look at the case of a customer wanting to include additional information which describes whether the employee has a company vehicle and the year that the employee started working with the company.

    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

    - 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...
    - Creating the Blog Script for a PHP/MySQL Blo...

    BlackBerry VTS




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