S
scion111
For maintaining address info, I currently have 3 tables, called
Contacts, Addresses and AddressTypes. Here are the fields in each table
(note: I'm not showing fields which do not pertain to this question):
Contacts:
Contact ID
First Name
Last Name
Contact Type ID
Addresses:
Address ID
Address Type ID
Contact ID
Address 1
Address 2
City
State
Zip
AddressTypes:
Address Type ID
Address Type
The primary key of the Contacts table Is Contact ID. The primary key
of the AddressTypes table Is Address Type ID. The primary key of the
Addresses table is a composite key based on Contact ID and Address Type
ID. I have a one to many relationship between the contacts table and
the Addresses table. I also have a one to many relationship between the
AddressTypes table and the Addresses table. Address types could be
home, work, mailing, etc.
I'm using the composite key to prevent a contact from having one
address type applied to two different addresses (i.e., the contact can
not have two addresses with the address type of 'home').
I'd like to add another table for Vendors, and utilize the same
Addresses table to store their address information. I could accomplish
this, I assume, by creating a one to many relationship between the
Contacts table and the Addresses table utilizing the Contact ID and
Address ID, and also creating a one to many relationship between the
Vendor ID (in my new table) and the Address ID in the Addresses table.
This would then eliminate the need for the Contact ID field in the
Addresses table.
However, if I remove the Contact ID field from the Addresses table, I
can't figure out how to prevent a contact or a vendor from being
allowed to have multiple addresses with the same address type (which I
accomplished before by using the composite primary key as explained
above).
I'm probably missing something simple, and I hope I've explained this
adequately. Any help or suggestions would be greatly appreciated!
Contacts, Addresses and AddressTypes. Here are the fields in each table
(note: I'm not showing fields which do not pertain to this question):
Contacts:
Contact ID
First Name
Last Name
Contact Type ID
Addresses:
Address ID
Address Type ID
Contact ID
Address 1
Address 2
City
State
Zip
AddressTypes:
Address Type ID
Address Type
The primary key of the Contacts table Is Contact ID. The primary key
of the AddressTypes table Is Address Type ID. The primary key of the
Addresses table is a composite key based on Contact ID and Address Type
ID. I have a one to many relationship between the contacts table and
the Addresses table. I also have a one to many relationship between the
AddressTypes table and the Addresses table. Address types could be
home, work, mailing, etc.
I'm using the composite key to prevent a contact from having one
address type applied to two different addresses (i.e., the contact can
not have two addresses with the address type of 'home').
I'd like to add another table for Vendors, and utilize the same
Addresses table to store their address information. I could accomplish
this, I assume, by creating a one to many relationship between the
Contacts table and the Addresses table utilizing the Contact ID and
Address ID, and also creating a one to many relationship between the
Vendor ID (in my new table) and the Address ID in the Addresses table.
This would then eliminate the need for the Contact ID field in the
Addresses table.
However, if I remove the Contact ID field from the Addresses table, I
can't figure out how to prevent a contact or a vendor from being
allowed to have multiple addresses with the same address type (which I
accomplished before by using the composite primary key as explained
above).
I'm probably missing something simple, and I hope I've explained this
adequately. Any help or suggestions would be greatly appreciated!