If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Composite primary key question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-21-06, 10:19
mburke mburke is offline
Registered User
 
Join Date: Aug 2006
Posts: 56
Composite primary key question

With this senario, I am thinking that only D is incorrect. Because A alone cannot define the key. C may be wrong, but I think it depends on the value of B. I assume if a FK can be null, but it's a composite, that it would be invalid if one part of the key is null and the other is not. What do you think?

Which of the following statement(s) is/are not True __d______:
In relation R ( A, B, C, D, E ) , A and B together are defined as primary key, S ( X, A, B, Y, Z) is another relation, and the A and B in relation S are the same attributes A, B correspondently in R.
a. As A and B are defined as primary key in R, so the values of A and B in R cannot be null.
b. Attribute A in R itself cannot be null.
c. Attribute A in S may be null.
d. A in S can be defined as foreign key reference to A in R.
e. A and B in S together can be defined as foreign key reference to A and B in R.
Reply With Quote
  #2 (permalink)  
Old 09-21-06, 18:42
certus certus is offline
Registered User
 
Join Date: Dec 2003
Location: Canada
Posts: 710
In C think about the fact that every time a record is generated for S it refers to R. Otherwise the database would be corrupted.

In D think about the fact that references even to composite keys deal with each attribute individually in the child table.
__________________
visit: relationary
Reply With Quote
  #3 (permalink)  
Old 09-22-06, 10:02
mburke mburke is offline
Registered User
 
Join Date: Aug 2006
Posts: 56
I am a bit confused. I assume a composite key elements are thought of as a whole. So if one key has a value and the other is null, then the reference is invalid. ...?
Reply With Quote
  #4 (permalink)  
Old 09-22-06, 10:30
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
composite key elements are indeed thought of as a whole

statement "e" is not necessarily true because the values of A and B in S might not be the same values as in R
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 09-22-06, 11:37
mburke mburke is offline
Registered User
 
Join Date: Aug 2006
Posts: 56
So it sounds like a reference back to R can be made using just one of the FK's A or B, rather than A and B?
Reply With Quote
  #6 (permalink)  
Old 09-22-06, 11:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
no, that's not it at all

which school is this? is there a book recommended for this course?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 09-22-06, 13:16
mburke mburke is offline
Registered User
 
Join Date: Aug 2006
Posts: 56
So then my original premise that D is wrong is correct?

As far as E goes, it can be correct if the sequence matches a componation in R?

The book is Database Design Using Entity-Relationship Diagrams, Sikha Bagui & Richard Earp

It does a poor job explaining composite keys. Do you know of a better source?
Reply With Quote
  #8 (permalink)  
Old 09-22-06, 13:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
> So then my original premise that D is wrong is correct?
that would've been my answer too

> As far as E goes, it can be correct if the sequence matches a componation in R?
i think so (but i do not know what a componation is)


> The book is Database Design Using Entity-Relationship Diagrams, Sikha Bagui & Richard Earp
can't say i've heard of it, but there are so many books out there...

> It does a poor job explaining composite keys. Do you know of a better source?
i learned from experience -- you get a real visceral understanding of how foreign keys work when you start working with them and getting the "ah ah, you can't do that" error messages when you screw up, as you will if you have composite keys and nulls...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 09-22-06, 13:33
mburke mburke is offline
Registered User
 
Join Date: Aug 2006
Posts: 56
Sorry, I meant 'Combination'


I did play around with FK's in MySQL. I was able to make invalid key combinations in the table that had the composite FK. I assume one would use a trigger to fix that in the real world.
Reply With Quote
  #10 (permalink)  
Old 09-22-06, 16:36
certus certus is offline
Registered User
 
Join Date: Dec 2003
Location: Canada
Posts: 710
The catch word is "defined". Is it defined logically, physically or in the DDL?
__________________
visit: relationary
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On