Connecting Tech Pros Worldwide Forums | Help | Site Map

Relationship question

Newbie
 
Join Date: Feb 2007
Posts: 1
#1: Feb 28 '07
I have a couple tables in a database. One for vendors and includes all the contact information you would expect. I also tables for customers and employees. A lot of the information seems to be the same for all three tables such as address and contact information. However if I try to use relationship to connect each of the three tables to a fourth table containing all the contact info I am unable to create a customer without creating a vendor linked to the same address. I have tried one-to-many relationships from the vendor or customer to the contact info table. I have also tried one-to-one.

Is there another type of relationship I can try or set it up in another way? I have thought about denormalizing the tables or just going without relationships altogether and just looking up the info using and id or something.


Any thoughts?

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,884
#2: Feb 28 '07

re: Relationship question


Create the tables as follows:

tblAddress
AddressID (Primary Key - Autonumber)
AddressLine1
AddressLine2
AddressLine3
PostCode
Country
ContactName
Telephone

tblVendor
VendorID (Primary Key)
VendorName
AddressID (Foreign key reference to Primary key of tblAddress)

tblEmployee
EmployeeID (Primary Key)
EmployeeName
AddressID (Foreign key reference to Primary key of tblAddress)

tblCustomer
CustomerID (Primary Key)
CustomerName
AddressID (Foreign key reference to Primary key of tblAddress)

tblAddress has a one to many relationship with each of the other tables.

Mary
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#3: Mar 3 '07

re: Relationship question


Your tblAddress should probably look something like this :
Expand|Select|Wrap|Line Numbers
  1. tblAddress
  2. AddressID (Primary Key - Autonumber)
  3. VendorID (Foreign Key)
  4. EmployeeID (Foreign Key)
  5. CustomerID (Foreign Key)
  6. AddressLine1
  7. AddressLine2
  8. AddressLine3
  9. PostCode
  10. Country
  11. ContactName
  12. Telephone
Each of the FK fields would have to be defined to allow Nulls and one, and only one, of the three should always be filled.
Reply


Similar Microsoft Access / VBA bytes