-1

I am developing an web application where I need to use Country-State-City dropdown for generating location based reports. I came across two approaches :-

  1. Option 1 - only one table-location is maintained to store country, state, city details

  2. Option 2 - Three different tables are maintained each for country, state and city

Note: In most cases when city is selected I also need to show its state and country, so in both cases I need to use joins as well. So which approach will result in better performance

mr. super cool
  • 196
  • 1
  • 12

2 Answers2

0

I would suggest to go for Option 2 to avoid load on database. Populate states on selection of Country or vise-versa and same for State - city.

rdiz
  • 6,136
  • 1
  • 29
  • 41
Gokul
  • 931
  • 7
  • 16
0

For sure Option 2 is much better. In one table you'll must to populate country name and state for each city - it is huge amount of duplicated items. Using separate tables for such things is called database normalization and it is strongly recommended to ensure data integrity and resistance to different kinds of mistakes.

Using denormalized tables is suitable for tasks when it is critical for select queries performance. But here you will no get any significant speed up. Moreover, you'll get reduced performance for such things as for example searching cities by partly typed country name, or getting states list for given country, etc..

You can check out also following discussions:

Community
  • 1
  • 1
oakymax
  • 1,454
  • 1
  • 14
  • 21