Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: [SQL 2000]Composite key (combination of PK from 2 tables) but allow null in the 2nd c

Started 1 month, 2 weeks ago by dee-u
To illustrate it better here is a sample data: Column1 Column2 R1 NULL R2 NULL R2 X1 R2 X2 R3 NULL As you can see the combined columns is unique, that is the requirement, is there a workaround that I can make a Composite Key out of those two tables? Another thing, those two columns are PK from other tables, with the first column there is no problem cascading updates, ...
Site: VBForums - Visual Basic and VB .NET Discussions and More!  VBForums - Visual Basic and VB .NET Discussions and More! - site profile
Forum: Database Development  Database Development - forum profile
Total authors: 3 authors
Total thread posts: 4 posts
Thread activity: no new posts during last week
Domain info for: vbforums.com

Other posts in this thread:

jmcilhinney replied 1 month, 2 weeks ago
I'm fairly sure what you're trying to do is not possible. I think you'd have to add an extra identity column to act as PK for the table and then make your two FK columns a unique key for the table, which I believe will allow nulls.

GaryMazzone replied 1 month, 2 weeks ago
PKs can not contain NULL values, so Jmcilhinney is correct what you want to do is not possible. Not leaving a null in the second column of the key.

jmcilhinney replied 1 month, 2 weeks ago
Here's an example of what I was talking about. Note that I set "Enforce Foreign Key Constraint" to False for the relationship between Table2 and Table3 in order to allow NULLs in the Table2ID column.

 

Top contributing authors

Name
Posts
jmcilhinney
2
user's latest post:
[SQL 2000]Composite key...
Published (2009-11-14 11:10:00)
Here's an example of what I was talking about. Note that I set "Enforce Foreign Key Constraint" to False for the relationship between Table2 and Table3 in order to allow NULLs in the Table2ID column.
dee-u
1
user's latest post:
[SQL 2000]Composite key...
Published (2009-11-13 02:48:00)
To illustrate it better here is a sample data: Column1 Column2 R1 NULL R2 NULL R2 X1 R2 X2 R3 NULL As you can see the combined columns is unique, that is the requirement, is there a workaround that I can make a Composite Key out of those two tables? Another thing, those two columns are PK from other tables, with the first column there is no problem cascading updates, but not so with the 2nd column, aside from a trigger is there any other trick...
GaryMazzone
1
user's latest post:
[SQL 2000]Composite key...
Published (2009-11-14 10:29:00)
PKs can not contain NULL values, so Jmcilhinney is correct what you want to do is not possible. Not leaving a null in the second column of the key.

Related threads on "VBForums - Visual Basic and VB .NET Discussions and More!":

Related threads on other sites:

Thread profile page for "[SQL 2000]Composite key (combination of PK from 2 tables) but allow null in the 2nd c" on http://www.vbforums.com. This report page is a snippet summary view from a single thread "[SQL 2000]Composite key (combination of PK from 2 tables) but allow null in the 2nd c", located on the Message Board at http://www.vbforums.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity