Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

Should I Populate Country/Region Names at DB or Application Level?

0

76 views

I'm going through a tough decision (at least for me)...

My website would have a list of countries in dropdown list and list of cities based on chosen country. I decided to populate the list at db level as:

CREATE TABLE Country
(
    countryID - PK
    countryName - FK
);


CREATE TABLE City
(
    cityID   - PK
    countryID - FK
    cityName
);

CREATE TABLE Register
(
    registerID - PK
    cityID - FK

)

However, this can add some complexity in php back-end coding when inserting record into registration as well as retrieving record from countries/cities, because on registration form user will city name on droplist, user won't see cityID, so i will have to fetch cityID based on chosen cityName, etc. Therefore, i said why do i just put the countries and cities list at application level in fixed drop down list and make register table look as:

CREATE TABLE Register
(
    registerID - PK
    cityName
)

cityName gets inserted directly without us having to join or call multiple tables and get specific ID for a city so we can then grab the cityName, etc...

I will only normalize in crucial tables such as making relationships between Member and Post/Thread tables. A member can have multiple threads one-to-many relationship. Otherwise, things that relate to multi-value as countries list won't be considered at DB level for simplicity and rap sake.

What do you think? Advice ...

asked January 9, 2011 9:13 am CST
posted via StackOverflow

3 Answers

0
 

I would suggest defining XML with the country name/id as the element and city names as the child elements. It makes it edit/read the xml data. I'm not sure whether you would like to consider this.

answered January 9, 2011 9:23 am CST
0
 

Not sure I understand the text of your question completely, but to answer the title of your question, I would keep country names in the database. Countries/Cities do change their names from time-to-time.

answered January 9, 2011 9:23 am CST
1
Best answer
 

The nature of the data should drive the database model. Not your front end issues.

Why not load your cities into a drop down list? Set the display text=cityName. Set the value=cityID.

answered January 9, 2011 9:39 am CST

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions
Application Distribution
December 26, 2010