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 |
|
mavericky
Posting Yak Master
117 Posts |
Posted - 2011-12-06 : 17:56:14
|
| hi,Table Aa intb inta and b together form primary keyTable Bc int (primary key)d intI want to create a foreign key such that,A.b = B.d.Is this possible, that d corresponds only to b even though the b is just part of the primary key?Thanks,Mavericky |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-06 : 23:40:27
|
| you can try and see for yourself that its not possible. Reason is since b is only part of pk you cant guarantee uniqueness of values in b to consider it as candidate key. However, if you add a separate unique constraint on b to guarantee uniqueness, then you can add fk from d to b------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jassi.singh
Posting Yak Master
122 Posts |
Posted - 2011-12-07 : 06:43:38
|
| Sql server will not allow you to create fk this way. To achieve this you need to separate it from pk and then add unique check constraint and then you can refer itJava Database |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-07 : 06:44:59
|
quote: Originally posted by jassi.singh Sql server will not allow you to create fk this way. To achieve this you need to separate it from pk and then add unique check constraint and then you can refer itJava Database
Why are you restating suggestions like this?This is same as what i posted yesterday------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2011-12-07 : 08:04:51
|
quote: Originally posted by visakh16
quote: Originally posted by jassi.singh Sql server will not allow you to create fk this way. To achieve this you need to separate it from pk and then add unique check constraint and then you can refer itJava Database
Why are you restating suggestions like this?This is same as what i posted yesterday------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Can't you just mark his answer as accepted and move on? http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|
|