FOREIGN KEY is used to establish the relationship among tables. FOREIGN KEY type can be Primary Key, Unique Key, or Normal Key of its table. Suppose, you want to manage data of authors and their books in the database. For this, you have a table named "author". The author table has columns like "author_id", "author_name" to store authors' info. To store books, you have another table named ">books". The books table has columns like "book_id", "book_name", and "author_id".

Because you have to keep track of books of each author in the book table, you created same type column ("author_id") in book table as in the author table so that relation can be established between these two tables using "author_id" columns. In the narrated example, author_id column of author table can be type of Primary Key and author_id column in books table can be type of Normal Key. Terminologically author table will be called ' master table' and books table will be called ' foreign table'. The author_id column in author table is a primary key and author_id column in books is a foreign key.

Foreign Key can be described as follow: A foreign key is a key found in a given table that references a primary key found in another table. Such keys are used to identify a relationship among rows in different tables.

Posted in: MySQL

Related FAQ's

Marius Ion ANGEL HOT SOFT LLC (800) 316-7677