Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
c0micrage
Starting Member
1 Post |
Posted - 2010-12-22 : 15:12:42
|
Hi,I am using sql server 2008 and created link tables for 1 to many and many to many. Example, patients can have many different stays in the hospital. So, I have a patients, hospitalstays, patientshospitalstays tables. Patients will have the PatientId primary key. HospitalStays wil have HosStayId as its primary key. The PatientsHospitalStays table will only PatientId and HosStayId columns. When I added the foreign relationship, it tells me to us unique contraints on the PatientId and HosStayId columns, but that will enforce uniqueness on those columns. The PatientId columns will contain multiple occurrance of the same PatientId value. How do I resolve this? |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2010-12-22 : 15:40:27
|
You may not need a link table at all. Assuming this is a one to many (and not many to many relationship), you could add foreign key column in the hospitalstays table which references the patientId column from the patients table. If a "hospital stay" is defined in such a way that many patients can share a single hospital stay, then you would need link tables etc. But, I can't visualize how that would be. (I cringe at the thought of more than one patient sharing even a single hospital room! :-)) |
|
|
|
|
|