(968 Views)

**FOREIGN KEY** is a key that is used to link two tables together. A FOREIGN KEY is a column or collection of columns in one table that refers to the PRIMARY KEY in another table. The table containing the PRIMARY KEY is called the child table and the table that contains the PRIMARY KEY is called the Parent Table.

**YES**, FOREIGN KEY column can contain null values. Null by definition means not a value. Null means that we do not yet know what the value of the column is.

For Example, we have three tables Pictures, Videos and Comments in an application which allows comments on pictures and also on videos. In comments table we have two Foreign Keys p_id and v_id along with the primary Key comment_id. So when you comment on a video only v_id would be required and p_id is not required so it would be null. Also,if you comment on a picture only p_id would be required and v_id would be null.

**YES**, FOREIGN KEY column can contain duplicate values. FOREIGN KEY can be used for One to Many Relationship.

For Example, we have an order table and the order details table. If any customer orders five items, he has one order and five order detail records that contain the same orderID as the FK.

1 UpvotesUpvote |
0 DownvotesDownvote |

- Double Hashing Algorithm [334 Views]
- Algorithm to find Maximum of 3 numbers [12944 Views]
- Python Program to Find Prime Factors of a Number [1934 Views]
- Flowchart and Algorithm for calculating X to the Power of Y i.e X
^{Y}[1792 Views] - Algorithm and Flowchart for Area of Triangle [2226 Views]

- How To Win Ludo King Game Every Time [34906 Views]
- Algorithm to find whether number is Armstrong Number or Not [34288 Views]
- Knuth-Morris-Pratt (KMP) Substring Search Algorithm with Java Example [25544 Views]
- Jio Phone hang on LOGO problem Solution - Hard Reset Jio Phone [24308 Views]
- FlowChart and Algorithm to find Whether a Number is Even or Odd [17984 Views]

**Looking for any Software or Tutorial?**

Don't Worry, we will find it for you

Contact Now