» » Foreign key in database

Foreign key in database

posted in: Information Technology | 0
Spread the love

A foreign key is generally a primary key from one table that appears as a field in another where the first table has a relationship to the second.

For example if we had a table A with a primary key X that linked to a table B where X was a field in B, then X would be a foreign key in B.

An example might be a student table that contains the course_id the student is attending. Another table lists the courses on offer with course_id being the primary key. The 2 tables are linked through course_id and as such course_id would be a foreign key in the student table.

Foreign keys are both a method of ensuring data integrity and a manifestation of the relationship between tables. It is also known as referential integrity.

Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values. We can have more than one foreign key in a table.

It allows referencing another table using the primary key for the other table.

A foreign key is a key used to link two tables together.

A foreign key is a field (or collection of fields) in one table that refers to the primary key in another table.

The table containing the foreign key is called the child table, and the table containing the candidate key is called the referenced or parent table.

The foreign key constraint is used to prevent actions that would destroy links between tables.

Follow Iswarya:

Latest posts from

Leave a Reply