PDA

View Full Version : foreign key clarification plz.


bazz
07-20-2007, 04:41 PM
Building (normalising) my Db, I have a query for you guys...

If the admin person queries tbl_premises, can they automatically get the country data from tbl_country by use of foreign keys, or, must they query tbl_country directly. Maybe it would work both ways but which would be more efficient/quicker/'shortest perl code'?

Bazz

tbl_country
| countryID | Name of Country |

tbl_admin
| adminID | First Name | Last Name | CountryID (FK) |

tbl_premises
| PremisesID | Premises Name | CountryID (FK) |

guelphdad
07-20-2007, 05:33 PM
you wouldn't use any perl code, you would get the data you need directly from your tables using sql.

you would do a join on the two tables and you could display
premisesID, premises name and nameofcountry without having to display the countryid field.

Fumigator
07-20-2007, 05:35 PM
You're talking about a join I guess?

SELECT p.premisesname
,c.nameofcountry
FROM tbl_premises as p
JOIN tbl_country as c
ON p.countryID = c.countryID

bazz
07-20-2007, 06:08 PM
Thanks both of you. :thumbsup:

I'll look into how to use that and see how I can make it output to my page, presumably, by putting the value into a variable.

bazz