Hi guys, firstly I'm new here so let me say hello.
Secondly, I'm not wholly proficient with databases (I'm learning SQL, MySQL and PHP for other things) however, I'm not a complete noob.
Anyways, on to the problem.
I need to create a Contact / Company / Project database. I think I have normalized the database but am a little unsure with some things (explained later). Basic layout is:
Tables:
Head Office Group
Head Office Contacts
Company
Contacts
Projects
Leave / Join dates
Head Office group can have one or more companies assigned
Head Office group can have one or more Head Office contacts assigned
Head Office Contacts can have one or more Companies assigned
Company can have none, or only one Head Office Group assigned
Company can have none, one or more Head Office Contacts assigned
Company can have one or more Contacts assigned
Company can have none, one or more Projects assigned
Company can have none, one or more Leave / Join dates per none, one or more Projects
Contacts can have none, one or more Projects assigned (for purposes of who deals with specific project that is assigned to related Company)
(please note I have left out Foreign Keys until I have confirmed a relational structure with following tables)
tbl: Head Office Group
headofficeID (auto# PK)
nickname
company_name
building_name
building_number
area
street
city
postcode
telephone
tbl: Head Office contacts
headcontactID (auto# PK)
title
forename
surname
position
extension (related to head office telephone)
mobile
tbl: Company
companyID (auto# PK)
nickname
company_name
building_name
building_number
area
street
city
postcode
telephone
tbl: Contacts
contactID (auto# PK)
title
forename
surname
position
extension (related to company telephone)
mobile
tbl Projects
projectID (auto# PK)
projectname
tbl Leave Join Dates
projectdateID (auto# PK)
projectID (FK)
companyID (FK)
joindate
leavedate
leave reason
Hopefully this is laid out correctly? Now I just need to come up with the correct relations and foreign keys for some potential queries that are troubling me:
1) I may need to display full company details, also displaying which Head Office the company is assigned to, while also showing all contacts assigned to the company (including Head Office contacts and which project they are assigned to)
Do I need a separate Head Office contacts table, or is there some way to assign a contact to either Head Office or just Company? (ie maybe a join table like [id]-[contactID]-[headofficeID]-[companyID] (but this would then leave a blank in either headofficeID or companyID fields, and potentially have more than one row if the contact is assigned to one Head Office but multiple companies?)
2) Would the above layout allow me to correctly audit when a company joins a specific project, then leaves the project, then joins again and so on?
I'm fairly sure the above is fine, although I know it needs a few extra join/link tables in somewhere - hopefully some good soul can give me a hand with this? Also please feel free to tear it apart and correct me in any way you see fit if I'm entirely wrong with any of this
Thanks