I'm afraid I'm very new to this and really struggling.
I have a table with a compound primary key composing of Code, Date, Client to represent an attendee on a course.
I need to include a 'Lead Client' column to represent a recursive relationship where one attendee can be nominated to lead others attending the same course – i.e. can lead other attendees with the same Code and Date only. The Code and Date need to be the same for the Lead Client as for the Client.
At the moment I have set up a composite Foreign Key in the table which references the Primary Key of the same table and comprises of 3 columns: Lead_Code, Lead_Date and Lead_Client.
I have set up the FK so that either all or none are null, and have set up the Lead_Code and Lead_Date so that their values must match the Code and Date of the same record.
However - this does not seem to be a very tidy or efficient way of storing the data, as each row where a Lead_Client is listed will basically contain two columns containing the same Code, and two containing the same Date. It also means that anyone inserting data into the table will need to enter the Code and Date twice wherever a Lead_Client is listed. I can't help feeling that there must be a simpler solution but I can't work it out.
Ideally I would like to simply include a 'Lead Client' column, but somehow force the table to only accept values where Lead_Client belongs to a record as the Client (as part of the PK) where the Code and Date match the Code and Date of the original Attendee record.
Code CRS1 Date 01/10 Client AA Lead_Client Null
Code CRS1 Date 01/10 Client BB Lead_Client AA
Code CRS2 02/10 Client CC Lead_Client AA = NOT ALLOWED as Client AA is not an attendee on course Code CRS2 on Date 02/10
Apologies if this doesn’t make sense – I’d be really grateful for any help on this as I’m really stuck.
January 1, 2011 11:53 PM
January 3, 2011 1:49 PM