This comes up a lot for me. In SQL Server 2008, I have 3 tables. 2 with unique keys and 1 which is a mapping between them. Example:
People Events Schedule
------ ------ --------
PersonId EventId ScheduleId
Name Place PersonId
EventId
Rsvp
ScheduleId
isn't needed if I make a composite key. I know how to make a composite key like this
ALTER TABLE Schedule ADD CONSTRAINT CK_Schedule_PersonId_EventId
UNIQUE NONCLUSTERED (PersonId, EventId)
but I don't know how to make one that also maps correctly to the foreign keys. How can I do this? Also, if I'm wrong and the ScheduleId
way is preferred, please say why.