Relational Dependencies: You make the Call....

  • Thread starter Thread starter WWGD
  • Start date Start date
Click For Summary
SUMMARY

This discussion focuses on the normalization of a database involving fields such as CompanyCity, CompanyState, and CompanyZip. The key dependency identified is that CompanyCity and CompanyState together determine CompanyZip, while CompanyCity alone does not due to cities sharing names across different states. To achieve proper normalization, the conversation suggests creating a table structure that includes CityName, CityState, CityZip, and CityPK, with foreign keys in the Companies table. The normalization process should follow the stages from First Normal Form (1NF) to Fifth Normal Form (5NF), ensuring all functional dependencies are appropriately managed.

PREREQUISITES
  • Understanding of database normalization principles, including 1NF, 2NF, 3NF, 4NF, and 5NF.
  • Familiarity with functional dependencies and primary keys in relational databases.
  • Knowledge of table design and foreign key relationships in SQL databases.
  • Experience with handling multi-valued fields and many-to-many relationships in database schemas.
NEXT STEPS
  • Research "SQL database normalization techniques" to deepen understanding of normalization stages.
  • Learn about "functional dependencies in relational databases" to clarify how they affect table design.
  • Explore "foreign key constraints in SQL" to understand their role in maintaining data integrity.
  • Investigate "many-to-many relationships in database design" to effectively manage complex data associations.
USEFUL FOR

Database designers, software developers, and data architects who are involved in database normalization and optimization will benefit from this discussion.

WWGD
Science Advisor
Homework Helper
Messages
7,772
Reaction score
13,002
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
We have many threads on AI, which are mostly AI/LLM, e.g,. ChatGPT, Claude, etc. It is important to draw a distinction between AI/LLM and AI/ML/DL, where ML - Machine Learning and DL = Deep Learning. AI is a broad technology; the AI/ML/DL is being developed to handle large data sets, and even seemingly disparate datasets to rapidly evaluated the data and determine the quantitative relationships in order to understand what those relationships (about the variaboles) mean. At the Harvard &...

Similar threads

Replies
65
Views
5K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 26 ·
Replies
26
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K