Re: Foreign Keys Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2008-12-11 at 13:27 -0500, Bastien Koert wrote:
> On Thu, Dec 11, 2008 at 12:56 PM, tedd <tedd.sperling@xxxxxxxxx> 
> >
> > I believe I can create the Course table (excluding everything not germane)
> > like so:
> >
> > INDEX (student_id),
> > FOREIGN KEY (student_id)
> >   REFERENCES (students(id)),
> > INDEX (instructor_id),
> > FOREIGN KEY (instructor_id)
> >   REFERENCES (instructors(id)),
> >
> > But how do I use Foreign Keys to retrieve data? What is the specific query
> > to pull out data from all three tables at once?
> >
> > Does anyone have any example code to show me the actual syntax?

> Nope, You can't use Fks for this. Foreign keys are constraints and are used
> to limit the data in the table. If you were to put an FK on the courses
> table referencing the instructors table on the instructor id, the instructor
> id must exist in the instructor table before db will allow the entry of the
> instructor id in the courses table. The idea is to force data integrity in a
> system such that certain records can't be created without having
> the necessary backup data from another table.
> Joins should allow you to pull the data from the table in one query

You want to be careful using joins though. If you were to pull all that
data in one shot using joins you would create a large data transfer
mostly containing redundant data.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux