Re: Primary Keys and Foreign Keys
Date: Sun, 07 Sep 2003 02:07:59 -0400
Message-ID: <3339781.1062914879_at_dbforums.com>
Originally posted by David
> 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.comReceived on Sun Sep 07 2003 - 08:07:59 CEST