Parent Child Relationships

  • I have a requirement to store the address for an object in two separate tables -- one for State and one for City. There should also be a parent, child relationship between the two.

    I am a little confused about what would be the best way to do this, and would appreciate any help that this forum can offer.

    Should I just put the FK for City and State in the object's table and the FK for State in the City's, or am i going about this completely wrong? Thank you.

  • is this for homework or an interview? kinda sounds more like homework

    can you post the table DDL for the tables you are trying to match up? Please see the link in my signature for the proper forum etiquette on posting questions


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • rpnew (3/22/2012)


    I have a requirement to store the address for an object in two separate tables -- one for State and one for City. There should also be a parent, child relationship between the two.

    I am a little confused about what would be the best way to do this, and would appreciate any help that this forum can offer.

    Should I just put the FK for City and State in the object's table and the FK for State in the City's, or am i going about this completely wrong? Thank you.

    i think what the requirement is stating is that your City Table needs to have a Foreign key to your State table;

    the the application could alow them to select the city, and the State would follow automatically...

    similarly a ZipCode table could have FK to tbcity(which links to County, which links to State), so that city,county,state are all selected based on the zip code, but that woudl require that county and state are not allowed to be null in the City table...

    you'd have Springfield, CT, Springfield, Oh, Springfield , MA in there, as examples if you did the entire US cities.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply