dbTalk Databases Forums  

Re: Primary Keys and Foreign Keys

comp.databases.theory comp.databases.theory


Discuss Re: Primary Keys and Foreign Keys in the comp.databases.theory forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
rupali007
 
Posts: n/a

Default Re: Primary Keys and Foreign Keys - 09-07-2003 , 01:07 AM







Originally posted by David

Quote:
I am trying to write SQL statements for the following tables.



Person (Person_ID, Name, Age, Interests)

House (House_ID, Name/Number, Address, City)

Lives (Person_ID,House_ID, Time_Lived_At_House)



In the 'Lives' table, I have defined Person_ID and House_ID as a
composite

primary key, is this correct?

Do I need to set Person_ID in Person and House_ID in House as a
foreign key

to reference the composite key in 'Lives'?



Please could someone help answer these questions



Thank you

David


hi david,



basically foreign key are used for referencing other table.for that
between any two tables if u want create referencing relation then
necessary condition is that both tables should have one feild common as
u have House_ID

and Person_ID in two tables common and these should be primary key in
any one of the table.



so u have ur two tables as House and Lives there is House_ID which is
composite primary key so setting that feild in any either of both
table as foreign key it will work out.similar is the case with other
two table Person and lives. so i hope this solve ur query if u have
still any doubt

wrie to me.



bye


--
Posted via http://dbforums.com


Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.