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

- Xeround Releases Free Version of MySQL Cloud...
- Oracle Announces New MySQL Specialization
- Constant Contact Chooses SkySQL for MySQL Su...
- Revoke Statement in MySQL
- The Grant Statement in MySQL
- SuccessBricks Announces ClearDB Availability...
- Building a PHP ORM: Deploying a Blog
- TROSYS Launches Free MySQL Manager and Admin...
- Building an ORM in PHP: Domain Modeling
- Building an ORM in PHP
- MySQL Leads Open Source Market, Gets Cluster...
- Oracle Announces Milestone Release for MySQL
- How to Stop SQL Injection Attacks
- New Defragmentation Solution for SQL Server
- Comparison of MyISAM and InnoDB MySQL Databa...


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

Dev Shed Tutorial Topics: