---
title: "Foreign Key (Self Reference) Constraint"  
description: "Foreign Keys represent relationships between tables. A foreign key is a column (or a group of columns) whose values are derived from the primary key o"  
author: "Amit Singh"  
published: 2011-05-18  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/174/foreign-key-self-reference-constraint  
category: "database"  
tags: ["database"]  
reading_time: 2 minutes  

---

# Foreign Key (Self Reference) Constraint

**[Foreign Keys](https://www.mindstick.com/forum/159031/how-can-i-list-all-foreign-keys-referencing-a-table-in-sql-server)** represent [relationships](https://www.mindstick.com/blog/11850/how-to-build-stronger-relationships-with-your-employees) between tables. A foreign key is a column (or a group of columns) whose values are derived from the [primary key](https://www.mindstick.com/blog/214/primary-key) or [unique key](https://www.mindstick.com/interview/768/what-s-the-dot-net-datatype-that-allows-the-retrieval-of-data-by-a-unique-key) of some other table.\

The table in which the foreign key is defined is called a **foreign table** and such table in which primary key defined and referenced by the foreign key is called the **primary table(master table)**.\
**Foreign key** can be defined in either a CREATE [TABLE statement](https://www.mindstick.com/forum/159777/how-to-add-a-new-column-to-an-existing-sql-table-using-the-alter-table-statement) or an [ALTER TABLE](https://www.mindstick.com/forum/811/alter-table-with-a-default-sql-server-vs-oracle) statement.\
Using in query as ***References TableName.ColumnName.***

##### Features of Foreign Keys

**1)** Foreign key is a column(s) that references a column(s) of table and it can be the same table also\
**2)** Parent that is being referenced has to be unique or primary key\
**3)** Child may have duplicates and nulls but unless it is specified\
**4)** [Foreign key constraint](https://www.mindstick.com/interview/90/what-is-a-constraint) can be specified on child but not on parent\
**5)** Parent record can be delete provided no child record exist.\
**6)** Master table(primary table) can not be updated if child record exist.

This constraint establishes a [relationship](https://yourviews.mindstick.com/view/80835/phubbing-is-the-relationship-killer) between records (column data) across a primary table (master table) and foreign table. This relationship ensures:\
1) Records can not be inserted into a foreign table if corresponding records in the master table do not exist.\
2) Records of the master table can not be deleted if corresponding records in the foreign table actually exist.

---

Original Source: https://www.mindstick.com/blog/174/foreign-key-self-reference-constraint

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
