Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6952119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:18:26+00:00 2026-05-27T14:18:26+00:00

I have a very basic question regarding the design of a database. I thought

  • 0

I have a very basic question regarding the design of a database. I thought I knew the answer, but after seeing an online tutorial on a triple dropdown menu and the design of the demo database, I’m not so sure anymore.

Ok here’s the setup, there are three tables involved.

First table: tblcountry
Fields: country_id
country

Second table: tblstate
Fields: state_id
country_id
state

Third table: tblcity
Fields: cidy_id
state_id
city

Now my question is: In table three, is it necessary to include the countryid as well? By using SQL you can query which country the city is in….or is it good design to have a reference to the country in the city table??

I hope someone can help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:18:27+00:00Added an answer on May 27, 2026 at 2:18 pm

    Normalization starts with data. In what follows, take the word state loosely. I’m talking about data analysis and normalization, not about modeling political hierarchies.

    country_name               state_name  city_name
    --
    United States of America   Alabama     Birmingham
    United States of America   California  Atascadero
    United States of America   Florida     Key Largo
    United States of America   Illinois    Carbondale
    United States of America   Kentucky    Winchester
    United States of America   Michigan    St. Louis
    United States of America   Ohio        Coldwater
    United States of America   Montana     Glasgow
    United States of America   Louisiana   Jefferson
    United States of America   Wisconsin   Jefferson
    Bulgaria                   Montana     Montana
    Costa Rica                 San José    San José
    Argentina                  Entre Rios  San José
    Uruguay                    San José    San José de Mayo
    

    It means “City [city_name] is in state [state_name] of country [country_name].” (What a table means is called its predicate.)

    This table effectively identifies the “full name” of a city as {country_name, state_name, city_name}. At the conceptual level, it’s not very different from using {last_name, middle_name, first_name} to identify a person. The difference is that, although two people often do share the same full name, two cities don’t.

    It’s clear there’s only one candidate key: {country_name, state_name, city_name}. This table is in 5NF. Substituting ID numbers for text can’t change that.

    Now, what’s the first thing you think after you’ve normalized a table to 5NF, and that table turns out to be “all key”? Is it, “Ok, now I need to split the key into more tables?”

    I hope not.

    To increase data integrity, you can project sensible subsets of the columns, and set foreign key references. Projection, used in this way, has absolutely no effect on the normal form of the original table. If it were in 2NF before this kind of projection, it will be in 2NF after this kind of projection. These tables have slightly different predicates from the original. (Duh.)

    -- Predicate: "State [state_name] is in country [country_name]."
    -- This table is also in 5NF.
    create table states (
      country_name varchar(35) not null,
      state_name varchar(15) not null,
      primary key (country_name, state_name)
    );
    
    insert into states
    select distinct country_name, state_name
    from cities;
    
    alter table cities
    add constraint cities_fk1
    foreign key (country_name, state_name)
      references states (country_name, state_name);
    
    -- Predicate: "[country_name] is a country."
    -- This table is also in 5NF.
    create table countries (
      country_name varchar(35) primary key
    );
    
    insert into countries
    select distinct country_name 
    from states;
    
    alter table states
    add constraint states_fk1
    foreign key (country_name)
      references countries (country_name);
    

    To select countries for populating a drop-down list, you can just

    select country_name
    from countries
    order by country_name;
    

    The user having chosen a country, selecting states is simple.

    select state_name
    from states
    where country_name = '?'
    order by state_name;
    

    And choosing city names is similar.

    select city_name 
    from cities
    where country_name = '?' 
      and state_name = '?'
    order by city_name;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very basic question - but I couldn't find an answer. I have got a
A very basic question, but after reading the Design Patterns: Elements of reusable OO
This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
I have a basic question regarding timers. My timer is acting very strange. I
I have very basic question regarding return value of a function, and checking the
I have a very basic question regarding properties in Objective-C. I can only access
I'm a perl noob and I have a very basic question regarding the @INC
I have a very, i think basic, question regarding CSS with floating div objects.
I've been reading through stuff on html5 but have a very basic question: what
quick and very basic newbie question. If i have list of dictionaries looking like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.