D
DanC
Hello everyone,
I'm in the process of designing my first database. I've been doing a
good bit of research and studying, but I haven't been able to find a
solution to my current dilemma. The short version is that I have one
table with a two-field primary key that should have a 1-to-many
relationship to another table with a three-field primary key. The two
fields for the first key are both in the second key. I can create the
relationship, but cannot enforce referential integrity. When I try to
do so, I get an error saying, "No unique index found for the
referenced field of the primary table." I don't understand why this
is happening or how to fix it.
The longer version, with table definitions:
The database deals with grant accounting. I work in a department that
does medical research that is funded by federal grants. Some grants
(but not all) are split into "cores", which are basically projects.
We hire on a number of contractors to assist with our research, but
some contractors work on more than one grant, and some work on more
than one core in the same grant.
The four tables most relevant to this issue are below:
t_Consultants
*EntID (PK)
*ConsFirstName
*ConsLastName
*ConsDateCreated
*ConsDateUpdated
t_ConsAlloc
*EntID (PK)
*GrantID (PK)
*CoreName (PK)
*ConsStartDate
*ConsEndDate
*ConsAllocDateCreated
*ConsAllocDateUpdated
t_Cores
*GrantID (PK)
*CoreName (PK)
t_Grants
*GrantID (PK)
*GrantName
*GrantYear
*GrantStartDate
*GrantEndDate
*IDC
What I want to do is create a 1-to-many relationship with referential
integrity enforced between the GrantID and CoreName fields, from the
t_Cores table to the t_ConsAlloc table. When I try to do this, I get
the error mentioned above (no unique index found...).
If I had to guess, the fact that CoreName can be null in t_ConsAlloc
is the big issue here. I can't find a good way around it (aside from
defining a nonexistent core for each grant that doesn't have cores)
because EntID and GrantID aren't enough to define a unique entry, yet
many grants don't have cores. Also, the related fact that there will
be grants in t_ConsAlloc that are not in t_Cores may also be an issue.
Thank you to anyone who read this far. I appreciate any help in
advance.
--DanC
I'm in the process of designing my first database. I've been doing a
good bit of research and studying, but I haven't been able to find a
solution to my current dilemma. The short version is that I have one
table with a two-field primary key that should have a 1-to-many
relationship to another table with a three-field primary key. The two
fields for the first key are both in the second key. I can create the
relationship, but cannot enforce referential integrity. When I try to
do so, I get an error saying, "No unique index found for the
referenced field of the primary table." I don't understand why this
is happening or how to fix it.
The longer version, with table definitions:
The database deals with grant accounting. I work in a department that
does medical research that is funded by federal grants. Some grants
(but not all) are split into "cores", which are basically projects.
We hire on a number of contractors to assist with our research, but
some contractors work on more than one grant, and some work on more
than one core in the same grant.
The four tables most relevant to this issue are below:
t_Consultants
*EntID (PK)
*ConsFirstName
*ConsLastName
*ConsDateCreated
*ConsDateUpdated
t_ConsAlloc
*EntID (PK)
*GrantID (PK)
*CoreName (PK)
*ConsStartDate
*ConsEndDate
*ConsAllocDateCreated
*ConsAllocDateUpdated
t_Cores
*GrantID (PK)
*CoreName (PK)
t_Grants
*GrantID (PK)
*GrantName
*GrantYear
*GrantStartDate
*GrantEndDate
*IDC
What I want to do is create a 1-to-many relationship with referential
integrity enforced between the GrantID and CoreName fields, from the
t_Cores table to the t_ConsAlloc table. When I try to do this, I get
the error mentioned above (no unique index found...).
If I had to guess, the fact that CoreName can be null in t_ConsAlloc
is the big issue here. I can't find a good way around it (aside from
defining a nonexistent core for each grant that doesn't have cores)
because EntID and GrantID aren't enough to define a unique entry, yet
many grants don't have cores. Also, the related fact that there will
be grants in t_ConsAlloc that are not in t_Cores may also be an issue.
Thank you to anyone who read this far. I appreciate any help in
advance.
--DanC