* shimak > How to use foreign key in mysql. > I am using mysql 3.23.36
Just do it... :) A foreign key is a field in a table referencing the primary key of another table. In mysql you don't need to specify which columns are foreign keys, you just use them in a join, and mysql will do the rest. Consider this basic schema: Person: id int, name varchar(30) Phone: phone varchar(15),person int The Person table contains person, each person have an unique id, defined as the primary key. The Phone table contains phone numbers. The phone column is the primary key for the Phone table, two different persons can not have the same phone number in this schema, but some persons may have multiple phone numbers. The person column of the Phone table is an integer, and in this imaginary application, this is used as a foreign key to the Person table. Mysql does not need to know this, it is resolved when we do a query: SELECT name,phone FROM Person,Phone WHERE name LIKE "Baklund%" AND Phone.person = Person.id; The final row of this query takes care of the foreign key relationship. <URL: http://www.mysql.com/doc/J/O/JOIN.html > I should also mention the consept of forreign key constraints, the possibility to tell mysql which column is a foreign key to which table, and to make mysql enforce the integrity of the relationship. This is rather new in mysql, available from version 3.23.43b. <URL: http://www.mysql.com/doc/S/E/SEC445.html > -- Roger --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php