Hi Dave,
As Bruce pointed out, your tblProject needs a little work. It should only
contain information specific to a project. I think you have properly
identified entities that are important - Projects, Sites, Equipment. So I
would start with creating those three "ENTITY" tables. Then, to glue them
into a relational database model that emulate your real world problem, you
would need more tables <g>. These additional tables reflect the
relationships between your "entity" tables (i.e. sometimes called "LINK" or
"JUNCTION" tables). Hence, whether or not you need "junction" tables depends
on the relationship among your "entity" tables. Many-to-Many relationship
between two entity tables requires a junction table.
There are some questions that only you can answer:
1. Can a site have multiple projects going on? If so, there is a
Many-to-Many between Projects and Sites
2. Can an equipment be involved (i.e. used) in multiple projects? If so,
there is a Many-to-Many between Projects and Equipment
I'm assuming the answer is yes to the questions above. In this case, two
alternatives for you to consider:
ALTERNATIVE ONE:
Entity Tables:
-tblProject (ProjectID PK, other fields such as Project Name, Project level
data, etc)
-tblSite (SiteID PK, other fields such as Site address, phone, etc..)
-tblEquipment (EquipmentID PK, other fields such as Equipment description)
Junction Tables:
-tblProjectSite between tblProject and tblSite (ProjectID FK, SiteID FK,
other fields such as start date, end date)
-tblProjectEquipment between tblProject and tblEquipment (ProjectID FK,
EquipmentID FK, other fields such as Equipment operator, etc.)
ALTERNATIVE TWO:
Entity Tables:
-tblProject (ProjectID PK, other fields such as Project Name, Project level
data, etc)
-tblSite (SiteID PK, other fields such as Site address, phone, etc..)
-tblEquipment (EquipmentID PK, other fields such as Equipment description)
Junction Tables:
-tblProjectSite between tblProject and tblSite (ProjectID FK, SiteID FK,
other fields such as start date, end date)
-tblProjectSiteEquipment between tblProjectSite and tblEquipment(ProjectID
FK, SiteID FK, EquipmentID, Equipment operator, etc.)
There are other alternative designs (i.e. you could have a third
alternative - relate Project and Equipment first and then to Site), but
there is probably only one that's most appropriate, and that is, the one
that most closely approximate your real world. A few things to notice from
the above alternatives:
- For both alternatives, the "entity" tables are setup the same way. As a
matter of fact, no matter how many alternative designs you can come up with,
"entity" tables should remain the same.
- For each alternative, the "junction" tables are setup differently.
- The most appropriate model to use is the one where the setup of "junction"
tables most closely emulate your real life problem.
Using alternative one, you can assign an equipment to a project at anytime,
you can also assign a project to a site at anytime. In other words, you can
assign an equipment to a project without knowing ahead of time the site of
the project. Using alternative two, however, you can only assign an
equipment to a project only after the site has been determined.
As you can see, the setup of the junction tables (i.e. relationships) is
crucial in determining what you can and can not do. You will have to
carefully examine the interrelations between your entities (Project, Site,
Equipment). You can do this by thinking through your business requirements
and processes which are what you're trying to emulate. By the way, either
alternative will do the query requirement you specified (i.e. tracking
equipment by site or by project) and many more.
HTH,
Immanuel Sibero