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 |
ergot72
Starting Member
1 Post |
Posted - 2013-01-17 : 05:41:49
|
I have a database set up sort of like thisTable1(id, ...)Table2(id, ...)Comment(id, typeId, str)where typeId=1 means Table1 and typeId=2 means Table2what I want to do is to create foreign keys to Table1 and Table2 from Commentsort ofALTER TABLE Comment ADD CONSTRAINT FK_Comment_Table1 FOREIGN KEY(id, typeId) REFERENCES Table1 (id, 1);ALTER TABLE Comment ADD CONSTRAINT FK_Comment_Table2 FOREIGN KEY(id, typeId) REFERENCES Table2 (id, 2);Is it possible?If not, how should I set up the relations? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-17 : 05:55:43
|
nope not possible.only way to do this would be to enforce this referential logic by means of trigger/check constraint.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2013-01-17 : 18:54:25
|
You could try adding a TypeID column to Table1 and Table2, and then using that column name in the FK definition. |
|
|
|
|
|