Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Normalization question

Normalization question

Scheduled Pinned Locked Moved Database
questionhelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Roger Alsing 0
    wrote on last edited by
    #1

    Hi , i have a small normalization problem. imagine this: table User table City table Country each user can be related to a city , and each city can be related to a country (NOTE: my real problem does not invlove neither users or regions this is just a exampel) now to the problem. an User MUST always have a country , but he may or may not have a city assigned (incase the registration is incomplete... again , note the real world problem invloves products and different categories) it might be easy to say "why do you want to use something that hasnt been registered 100%" well.... i have no idea , this is just the way they work here, we sell products even if they havnt been completely registered.. so what would be the correct way to normalize such problem? should user also relate to country , even though it makes it possible to relate the user to "hungary" and relate the same user to the city "london" , which in turn relates to "england". OR should i insert an "empty" element in the city table for each country. so i can relate the user to an empty element that in turn relates to the correct country? OR is there any other "correct" way of doing this???

    S S 2 Replies Last reply
    0
    • R Roger Alsing 0

      Hi , i have a small normalization problem. imagine this: table User table City table Country each user can be related to a city , and each city can be related to a country (NOTE: my real problem does not invlove neither users or regions this is just a exampel) now to the problem. an User MUST always have a country , but he may or may not have a city assigned (incase the registration is incomplete... again , note the real world problem invloves products and different categories) it might be easy to say "why do you want to use something that hasnt been registered 100%" well.... i have no idea , this is just the way they work here, we sell products even if they havnt been completely registered.. so what would be the correct way to normalize such problem? should user also relate to country , even though it makes it possible to relate the user to "hungary" and relate the same user to the city "london" , which in turn relates to "england". OR should i insert an "empty" element in the city table for each country. so i can relate the user to an empty element that in turn relates to the correct country? OR is there any other "correct" way of doing this???

      S Offline
      S Offline
      slvrscremr
      wrote on last edited by
      #2

      Does the database platform you are using support stored procedures? Darien C#, VB.NET, Oracle, Sq(uirre)l Server "I don't know. I haven't tried today." - Trumpet icon Maynard Ferguson's response when asked how high he could play.

      R 1 Reply Last reply
      0
      • S slvrscremr

        Does the database platform you are using support stored procedures? Darien C#, VB.NET, Oracle, Sq(uirre)l Server "I don't know. I haven't tried today." - Trumpet icon Maynard Ferguson's response when asked how high he could play.

        R Offline
        R Offline
        Roger Alsing 0
        wrote on last edited by
        #3

        its ms sql . but what has storedprocedures to do with table normalization rules? //Roger

        S 2 Replies Last reply
        0
        • R Roger Alsing 0

          its ms sql . but what has storedprocedures to do with table normalization rules? //Roger

          S Offline
          S Offline
          slvrscremr
          wrote on last edited by
          #4

          Well.... I was brainstorming and trying to think about different ways you could ensure the integrity of the data. i.e. Allowing London, U.K. and disallowing Los Angeles, Nigeria... Darien "I don't know. I haven't tried today." - Trumpet icon Maynard Ferguson's response when asked how high he could play.

          1 Reply Last reply
          0
          • R Roger Alsing 0

            its ms sql . but what has storedprocedures to do with table normalization rules? //Roger

            S Offline
            S Offline
            slvrscremr
            wrote on last edited by
            #5

            Speaking strictly from a normalization perspective, since any given user can only have one city or state, I would probably have a CityId and a CountryId element in the users table. I would make the countryId NOTNULLABLE and the cityId NULLABLE. I would then have those two id columns referenced to two lookup tables ( tblCountryLkp, tblCityLkp ? ) that would contain valid entries for their specific entities. A stored procedure could then be used to reference another table ( tblValidCountryCities ? ) that would contain all valid combinations of cities and countries. Any insertion would be validated against this table and a non-conforming combination would result in an error. Hope this helps, Darien "I don't know. I haven't tried today." - Trumpet icon Maynard Ferguson's response when asked how high he could play.

            1 Reply Last reply
            0
            • R Roger Alsing 0

              Hi , i have a small normalization problem. imagine this: table User table City table Country each user can be related to a city , and each city can be related to a country (NOTE: my real problem does not invlove neither users or regions this is just a exampel) now to the problem. an User MUST always have a country , but he may or may not have a city assigned (incase the registration is incomplete... again , note the real world problem invloves products and different categories) it might be easy to say "why do you want to use something that hasnt been registered 100%" well.... i have no idea , this is just the way they work here, we sell products even if they havnt been completely registered.. so what would be the correct way to normalize such problem? should user also relate to country , even though it makes it possible to relate the user to "hungary" and relate the same user to the city "london" , which in turn relates to "england". OR should i insert an "empty" element in the city table for each country. so i can relate the user to an empty element that in turn relates to the correct country? OR is there any other "correct" way of doing this???

              S Offline
              S Offline
              Steven Campbell
              wrote on last edited by
              #6

              Consider removing city from your user table, and placing it in an associated user_city table (user_city_id, user_id, city_id). This makes it clear that the city is optional information that is not (reliably) part of the core user information.


              my blog

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups