Home arrow MySQL arrow Database Design Using Key-Value Tables

Database Design Using Key-Value Tables

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.

TABLE OF CONTENTS:
  1. Database Design Using Key-Value Tables
  2. Traditional database design vs. key-value table
  3. Drawback no. 1: No real use of database data types
  4. Drawback no. 2: Awkward use of database constraints
  5. Drawback no. 3: Problematic use of AND operator when relating to more than one attribute in the query criteria
By: Tal Olier
Rating: starstarstarstarstar / 34
February 13, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
   

MYSQL ARTICLES

- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates

 



© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap

Dev Shed Tutorial Topics: