473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Foreign Key Design...

Hello All,

I am relatively new to database design and wanted to ask a few
questions to see if I am on the right track regarding design and
normalization.

I am creating a user entity which is made up of 4 tables:

User(UserID(PK), EmpID, CountryID, PostCodeID)
Employee(EmployeeID(PK), EmployeeType)
Country(CountryID(PK), CountryName)
PostCode(PostCode(PK), CountryID(PK), City)

These are a few things I am trying to clarify
1) The Country table has a relationship with the User table via a
foreign key FKUser_CountryID, and the PostCode table has a relationship
with the User table via FKUser_PostCodeID_CountryID. I dont however
have any relationship between the Country and PostCode tables. Is this
okay or have I created these relationships incorrectly? My other
thinking was to create a location table:
Location(CountryID, PostCodeID, City)
Then the User table would have a relationship with location through the
Country and PostcodeID fields, and the Location table would have a
relationship with the Country table through the CountryID field?

2) There will be instances where the User is not an employee, so the
EmpID field will be null when no relationship exists between User and
Employee. Is it worth creating a boolean field in the User table called
IsEmployee to help checking in programs, or should I just rely on
checking whether the EmpID field is null in the User table.

3) Finally, much of the old data on the system has been created in
databases created many years ago. Unfortunately much of this old design
includes storage of redundant data, lack of constraints and no
normalization. However because many of the old programs would need to
be completely re-written if the schema of these tables were changed I
am really stuck using them. Does anyone have any advice on steps I
could take to improve the situtation.

I appreciate any help anyone can give me
Steve

Jul 27 '06 #1
3 1766
Looks like someone going normalization crazy. I mean, normalization is
good, but no need to go overboard. If a user need not be an employee,
just combine the Employee and User tables and put a boolean IsEmployee
field or whatever. The postal code gig. DO you really need this level
of normalization? How big is your database going to be?

Jul 27 '06 #2
Hi Steve,

No matter what others might say if you are going to design a database,
big or small, you may as well do it right.

There is no advantage in doing things in half measures, however it does
have to be said that you are taking things to extremes slightly. The
amount of time and effort it would take to efficiently program a
database to recognise the country from postcode, or city would be more
trouble than it is worth. I would suggest default values in the data
entry forms that you are going to use, and the storage of the address
in one table.

Good luck

Nick

Steven wrote:
Hello All,

I am relatively new to database design and wanted to ask a few
questions to see if I am on the right track regarding design and
normalization.

I am creating a user entity which is made up of 4 tables:

User(UserID(PK), EmpID, CountryID, PostCodeID)
Employee(EmployeeID(PK), EmployeeType)
Country(CountryID(PK), CountryName)
PostCode(PostCode(PK), CountryID(PK), City)

These are a few things I am trying to clarify
1) The Country table has a relationship with the User table via a
foreign key FKUser_CountryID, and the PostCode table has a relationship
with the User table via FKUser_PostCodeID_CountryID. I dont however
have any relationship between the Country and PostCode tables. Is this
okay or have I created these relationships incorrectly? My other
thinking was to create a location table:
Location(CountryID, PostCodeID, City)
Then the User table would have a relationship with location through the
Country and PostcodeID fields, and the Location table would have a
relationship with the Country table through the CountryID field?

2) There will be instances where the User is not an employee, so the
EmpID field will be null when no relationship exists between User and
Employee. Is it worth creating a boolean field in the User table called
IsEmployee to help checking in programs, or should I just rely on
checking whether the EmpID field is null in the User table.

3) Finally, much of the old data on the system has been created in
databases created many years ago. Unfortunately much of this old design
includes storage of redundant data, lack of constraints and no
normalization. However because many of the old programs would need to
be completely re-written if the schema of these tables were changed I
am really stuck using them. Does anyone have any advice on steps I
could take to improve the situtation.

I appreciate any help anyone can give me
Steve
Jul 27 '06 #3
Steven wrote:
3) Finally, much of the old data on the system has been created in
databases created many years ago. Unfortunately much of this old design
includes storage of redundant data, lack of constraints and no
normalization. However because many of the old programs would need to
be completely re-written if the schema of these tables were changed I
am really stuck using them. Does anyone have any advice on steps I
could take to improve the situtation.
Just off the top of my head...

Do the older programs still add records? If not, then perhaps you could
link to the older tables into a new mdb. Write queries that present
the old data in the format your new system will use. Group by (Totals)
queries might be a help, and/or you could use a large number of sub queries.

Where your new application must display old data with the new, use union
statements to combine new tables with the above queries. In procedures
where you're adding/editing new data, you probably only need the new tables.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Jul 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jamie Jackson | last post by:
I've got a field that can be a foreign key on the table *OR* the table depending on the value of (see "Structure," below). Question 1: Is this poor DB design? Question2: If this is okay DB...
10
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
31
by: Robert Brown | last post by:
Let's say I have a type hierarchy: (just an example) the general entity customer: CREATE TABLE customer(customer_id int, customer_name varchar(250), customer_type int) three specific...
1
by: Vinodh Kumar P | last post by:
I understand the number of foreign keys allowed is restricted by the DBMS I use. In a general relational schema design perspective how many foreign keys a table shall have? If I have large number...
26
by: pb648174 | last post by:
I have a table called BidItem which has another table called BidAddendum related to it by foreign key. I have another table called BidFolder which is related to both BidItem and BidAddendum, based...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
20
by: Dennis Gearon | last post by:
I am working on a design where a location for something can have: Fully qualified address with even building names, room numbers, and booth numbers. **-OR-** GPS location **-OR-** Both ...
5
by: Bob Stearns | last post by:
For good and sufficient reasons I wish to insure that a primary key of table 1 is not a primary key of table 2. The following does not work: ALTER TABLE IS3.AUCTION_SUPER_CATEGORIES ADD...
0
by: ckiraly | last post by:
Greetings everyone - I am new to MSSQL 2005, and have started a database design project for my company. The issue I have is in a specific instance of foreign key creation. Here is the whole...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.