Re: call the appropriate and correct database

Johan De Meersman <[email protected]>
Newsgroups gmane.comp.db.mysql.general
Message-ID <[email protected]>

----- Original Message -----
> From: "HaidarPesebe" <[email protected]>
> Subject: call the appropriate and correct database

> How do I call first database table as follows :
> 
> id | country | province | distric | cost
> ------------------------------------------------
> 1 | USA | Alanama | distrik | 20
> 2 | USA | Alabama | distrik2 | 22
> 3 | USA | Alabama | distrik3 | 22
> 4 | France | Paris | disrik4 | 30

You want to normalize your data by splitting that out into separate tables for country, province and district, and referencing the higher level instead. You'd get something like this:

| COUNTRIES     |
| c_id | name   |
|    1 | USA    |
|    2 | France |

| PROVINCES                 |
| p_id | c_id | name        |
|    1 |    1 | Alabama     |
|    2 |    1 | Washington  |
|    3 |    2 | Paris       |
|    4 |    2 | Nord-Calais |

| DISTRICTS              |
| d_id | p_id | name     |
|    1 |    1 | distrik  |
|    2 |    1 | distrik2 |
|    3 |    1 | distrik3 |
|    4 |    3 | distrik4 |


That way, you can fill your dropdowns by a simple, fast select statement. Whenever you need more complex bits, you can just join the tables as necessary.

Google for "database normalisation" for more info about this practice, and find information about "foreign keys constraints" to ensure consistency in your database.



-- 
Unhappiness is discouraged and will be corrected with kitten pictures.

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.