Relational Dependencies: You make the Call....

  • Thread starter Thread starter WWGD
  • Start date Start date
AI Thread Summary
The discussion centers on the normalization of a database involving the fields CompanyCity, CompanyState, and CompanyZip. It is established that the dependency CompanyCity + CompanyState leads to CompanyZip, while CompanyCity alone does not, due to cities sharing names across different states. Participants highlight that some cities, like New York City and Los Angeles, have multiple ZIP codes, necessitating a more complex table structure to accurately represent these relationships. To fully normalize the database, a suggested approach includes creating separate tables for city and ZIP code data, ensuring all fields depend on the primary key. The conversation emphasizes the importance of adhering to normalization rules to avoid data redundancy and maintain integrity.
WWGD
Science Advisor
Homework Helper
Messages
7,678
Reaction score
12,360
Hi all,
I am normalizing a database and I have the three fields: CompanyCity, CompanyState, CompanyZip
It seems clear to me that there is a dependency :

CompanyCity+ CompanyState --> CompanyZip

But CompanyCity --> CompanyZip is not a dependency, since there are cities with the same name in different states. My colleague says this says both are wrong. Just want to have someone impartial clear up this disagreement.
Thanks.
 
Technology news on Phys.org
Are there cities in the US with more than one zipcode? If there are, the first dependency is wrong. You would need a table with CityName, CityState, CityZip, CityPK, and then have a foreign key in the Companies table referring to CityPK.

(And to fully normalize, you could make two tables, one with CityName, CityState, CityPK, and a second table listing all the zip codes per city. Maybe overkill in most circumstances.)
 
Samy_A said:
Are there cities in the US with more than one zipcode? If there are, the first dependency is wrong. You would need a table with CityName, CityState, CityZip, CityPK, and then have a foreign key in the Companies table referring to CityPK.

(And to fully normalize, you could make two tables, one with CityName, CityState, CityPK, and a second table listing all the zip codes per city. Maybe overkill in most circumstances.)
Actually, now that you mention it, yes, in NYC, for one, there are different ZIPs for different parts of the city. So now I am thinking. And I know there is a similar issue in L.A , you know, the 90210 thing and all (though maybe, unlike me, you actually have a life and you don't know ;)) :

CompanyStAddress+CompanyCity+ CompanyState --> CompanyZip

Since once you know a region within a city, the ZIP is determined. But , as you correctly point out, CompanyCity+
 
In order to be sure that you're normalizing the tables of a database correctly, you must begin with the 1st NF and go your way, keeping track of what stage of normalizing you're at. I give the general guidelines from my own experience, just in case they could be of some help:
In order to get a table in 1NF, you have to get rid of repeated groups of fields (columns) so that the intersection of a raw and a column, always corresponds to a single value. If you are on 1st NF - if not, you have to go first to 1st NF, then to go to 2nd NF, you must get rid of all partial functional dependencies that exist in table fields. All fields not belonging to primary key, are solely dependent on the primary key, which in the usual case is comprised by more than one fields. With 2nd NF we effectively avoid field repetitions. In order to get to 3rd NF - table has to be already in 2nd NF, we must get rid of all the transitional dependencies that exist among its fields. In other words, in each and every table all fields must depend on the primary key - not through other fields. Now in order to go to 4th NF - provided you are on 3rd NF, we have to get rid of all functional dependencies that contain multi-valued fields. Finally, to go to 5th NF - again provided you are on 4th NF, you must get rid of all the remaining dependencies that block the breakup of the table in smaller tables, which if in turn breakup in even smaller ones and get combined appropriately, they can recreate the initial tables.
 
QuantumQuest said:
In order to be sure that you're normalizing the tables of a database correctly, you must begin with the 1st NF and go your way, keeping track of what stage of normalizing you're at. I give the general guidelines from my own experience, just in case they could be of some help:
In order to get a table in 1NF, you have to get rid of repeated groups of fields (columns) so that the intersection of a raw and a column, always corresponds to a single value. If you are on 1st NF - if not, you have to go first to 1st NF, then to go to 2nd NF, you must get rid of all partial functional dependencies that exist in table fields. All fields not belonging to primary key, are solely dependent on the primary key, which in the usual case is comprised by more than one fields. With 2nd NF we effectively avoid field repetitions. In order to get to 3rd NF - table has to be already in 2nd NF, we must get rid of all the transitional dependencies that exist among its fields. In other words, in each and every table all fields must depend on the primary key - not through other fields. Now in order to go to 4th NF - provided you are on 3rd NF, we have to get rid of all functional dependencies that contain multi-valued fields. Finally, to go to 5th NF - again provided you are on 4th NF, you must get rid of all the remaining dependencies that block the breakup of the table in smaller tables, which if in turn breakup in even smaller ones and get combined appropriately, they can recreate the initial tables.
I understand, that is precisely what I am trying to do. I believe the above is a dependency on non-keys: Company Name is the PK for Company, but CompanyZip is dependent on the three fields (We are restricting to major companies so that two companies having the same name is not an issue).
 
  • Like
Likes WWGD
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top