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 > Quick foreign key question..

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-20-09, 17:43
makko187 makko187 is offline
Registered User
 
Join Date: Nov 2008
Posts: 16
Quick foreign key question..

Hi,

I am studying for an upcoming exam and came across this question and it has me puzzled.

Code:
State two conditions about the attributes Employees.deptNum and Departments.deptNum – that must be satisfied in order for an RDBMS to accept Employees.deptNum as a foreign-key.
Does the question mean two conditions of the data entered or conditions of the attribute like type, length etc..?

First Case:
Code:
Both attributes must be of the same type and both tables (Employees and Departments) must be in the same database.
Second Case:
Code:
The data entered must be either null or else match one of the values in Employees.deptNum to be accepted as a foreign key..
Im not really sure how to answer this tbh.

How would you guys answer this?

Thanks..
Reply With Quote
  #2 (permalink)  
Old 07-21-09, 04:07
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
I don't believe this is to do with the data.

There is a condition that must be true for one of the attributes you mention.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #3 (permalink)  
Old 07-21-09, 04:57
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
second case is certainly true
for a foreign constraint the value must exist in the table referred to.
ie employees.deptID must exist in departments
however the second part (ie or null) depends on the definition of the column in the child table (ie if employee.deptID is allowed as nullable) then the second case rings true

the first case is more abstract, it could be true however Im pretty certain Ive come across a foreign key which didnt' use the same datatype (however the datatype could be coerced to the foreign key column/parent table column type (IIRC it was upsizing from an integer to a Big Integer) it wouldnt' work with decimals....

Generally I would expect a SQL engine to enforce foreign key constraints within the same physical database. although it may be possible in say MySQL to enforce a constraint against a different db.. but I've never had the need to try it so i dunno if it would work.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #4 (permalink)  
Old 07-21-09, 12:00
makko187 makko187 is offline
Registered User
 
Join Date: Nov 2008
Posts: 16
The question after that was about the data entered so i'm pretty sure this question is talking about the attributes condition.

@pootle flump: What condition must be true?
is it: Department.DeptNum must be a primary key?

second condition?could we say same type to get full marks for the question even though technically this is not the case?

Thanks for your help guys.
Reply With Quote
  #5 (permalink)  
Old 07-21-09, 12:16
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by makko187
is it: Department.DeptNum must be a primary key?
you're getting very warm, but you're not quite there yet

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 07-21-09, 12:22
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Quote:
Originally Posted by makko187
second condition?could we say same type to get full marks for the question even though technically this is not the case?
It's more a case of the physical implementation and whether or not automatic coercion is supported. TMK there is no requirement in the relational model - I admit it is too long since my school days to remember whether or not it explicitly forbids it.
I would suggest this is not really something to put into an academic paper.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
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