Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

limiting the number of possible entries into a composite key 1

Status
Not open for further replies.

MrsNic

Instructor
Feb 6, 2005
44
GB
I have a table that stores details of activities undertaken by students over a year (Maximum of 3 per year)

I have made a composite key that comprises of
studentID
ActivityID
Term
Year

This is fine, but it allows for errors e.g. a student can be entered for two different activities in the same term for the same year as this is not recorded as a duplicate. Any ideas how I can solve this? I have a feeling that it should be easy but I think I have been looking at it for too long!

Many thanks
Cath
 
You create an index that includes multiple fields.

Open the table in design mode. Open up the Indexes window - from the menu, "View" -> "Indexes".

Objective said:
a student can be entered for two different activities in the same term for the same year

Create a unique index, say idxOneActivity
[tt]
Index Name Field Name Sort Order

idxOneActivity StudentID
Term
Year
[/tt]
After creating the above, select idxOneActivity again, and take note of the bottom part of the window, Index Properties. Firstly, if you do not have a primary key set for this table, and the above makes sense, then this key as the primary index. Setting this index as the primary key will set the other fields correctly.

If this not to the primary key, then set Unique to Yes. You probably want to set Ignore Nulls to No.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top