I have three tables in my database: Contacts
(master table), Users
and Staff
. The Contacts
table has a primary key that is referenced as a foreign key from the Users
and Staff
tables.
Contacts
ContactID (Primary Key)
First Name
Last Name
Email
Users:
ContactID (Foreign Key)
Username
Password
Staff:
ContactID (Foreign Key)
Position
Comments
Pulling data from these tables is fairly simple with INNER JOIN
and depends what data you need from the Users
or Staff
table. Updating and inserting new records is something that I'm not sure which way to approach.
Since the Contacts
table is my master table and holds unique ID's but at the same time is shared between Users
and Staff
, I'm not sure about this situation.
Let's say I want to enter new user record. I need to enter First, Last name and email into the Contacts
table, and User Name and Password into the Users
table. At the same time I have to check if First, Last name and email already exist in the Contacts
table, since maybe this Contact
record has been previously entered for a Staff
record.
I'm not sure how to prevent duplicates but at the same time there might be user or staff with the same name. Should I limit/filter by email and not let them enter the records if the email already exist in contacts table? Or is there a better way to handle this?
The whole point of having three tables is to prevent redundant data since User
might be a Staff
, but Staff
might not be a User
if that make sense. If anyone can help me pick the best approach please let me know. Thanks