<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PostgreSQL-Database%2FC2%2FForeign-Key-Constraint%2FEnglish</id>
		<title>PostgreSQL-Database/C2/Foreign-Key-Constraint/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PostgreSQL-Database%2FC2%2FForeign-Key-Constraint%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;action=history"/>
		<updated>2026-05-12T23:15:37Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;diff=57713&amp;oldid=prev</id>
		<title>ANJALISATDIVE at 10:17, 12 May 2026</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;diff=57713&amp;oldid=prev"/>
				<updated>2026-05-12T10:17:54Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 10:17, 12 May 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 33:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 33:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* '''PostgreSQL version 18.1''', and&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* '''PostgreSQL version 18.1''', and&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* '''PgAdmin4 version 9.11'''.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* '''PgAdmin4 version 9.11'''.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;EduPyramids periodically verifies the correctness of the tutorials for subsequent versions. Changes, if any, are explained through the Instruction Sheet.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|| To record this tutorial, I am using the following setup.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|| To record this tutorial, I am using the following setup.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>ANJALISATDIVE</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;diff=57712&amp;oldid=prev</id>
		<title>Madhurig at 07:08, 12 May 2026</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;diff=57712&amp;oldid=prev"/>
				<updated>2026-05-12T07:08:05Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;amp;diff=57712&amp;amp;oldid=57711&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Madhurig</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;diff=57711&amp;oldid=prev</id>
		<title>ANJALISATDIVE at 05:59, 12 May 2026</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;diff=57711&amp;oldid=prev"/>
				<updated>2026-05-12T05:59:39Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 05:59, 12 May 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 225:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 225:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;What is a Foreign key?'''&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;What is a Foreign key?'''&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|| &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/del&gt;A foreign key is a column that references a primary key in another table.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|| A foreign key is a column that references a primary key in another table.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* It creates a relationship between two tables in a database.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* It creates a relationship between two tables in a database.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* It ensures that the referenced value exists in the parent table.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* It ensures that the referenced value exists in the parent table.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>ANJALISATDIVE</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;diff=57710&amp;oldid=prev</id>
		<title>ANJALISATDIVE: Created page with &quot;   {| border=1 |- ! width=&quot;35%&quot; | '''Visual Cue''' ! width=&quot;65%&quot; | '''Narration'''  |- || '''Slide 1'''  '''Title Slide''' || Welcome to this Spoken Tutorial on '''Foreign Key...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PostgreSQL-Database/C2/Foreign-Key-Constraint/English&amp;diff=57710&amp;oldid=prev"/>
				<updated>2026-05-12T05:23:30Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;   {| border=1 |- ! width=&amp;quot;35%&amp;quot; | &amp;#039;&amp;#039;&amp;#039;Visual Cue&amp;#039;&amp;#039;&amp;#039; ! width=&amp;quot;65%&amp;quot; | &amp;#039;&amp;#039;&amp;#039;Narration&amp;#039;&amp;#039;&amp;#039;  |- || &amp;#039;&amp;#039;&amp;#039;Slide 1&amp;#039;&amp;#039;&amp;#039;  &amp;#039;&amp;#039;&amp;#039;Title Slide&amp;#039;&amp;#039;&amp;#039; || Welcome to this Spoken Tutorial on &amp;#039;&amp;#039;&amp;#039;Foreign Key...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;35%&amp;quot; | '''Visual Cue'''&lt;br /&gt;
! width=&amp;quot;65%&amp;quot; | '''Narration'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 1'''&lt;br /&gt;
&lt;br /&gt;
'''Title Slide'''&lt;br /&gt;
|| Welcome to this Spoken Tutorial on '''Foreign Key Constraint''' in '''PostgreSQL'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 2''' &lt;br /&gt;
'''Learning Objectives'''&lt;br /&gt;
|| In this tutorial, we will learn about:&lt;br /&gt;
* Foreign key constraint&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 3'''&lt;br /&gt;
&lt;br /&gt;
'''System Requirements'''&lt;br /&gt;
* '''Ubuntu 24.04 LTS'''&lt;br /&gt;
* '''PostgreSQL version 18.1''', and&lt;br /&gt;
* '''PgAdmin4 version 9.11'''.&lt;br /&gt;
|| To record this tutorial, I am using the following setup.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 4'''&lt;br /&gt;
&lt;br /&gt;
'''Pre-requisites'''&lt;br /&gt;
&lt;br /&gt;
|| To follow this tutorial,&lt;br /&gt;
&lt;br /&gt;
* Learners should have '''PostgreSQL''' and '''pgAdmin4'''&lt;br /&gt;
&lt;br /&gt;
* For the prerequisite '''PostgreSQL''' tutorials, please visit this website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 5'''&lt;br /&gt;
&lt;br /&gt;
'''Code Files'''&lt;br /&gt;
&lt;br /&gt;
The following code file is required to practice this tutorial:&lt;br /&gt;
* '''Fk-commands.txt'''&lt;br /&gt;
This file is provided in the Code Files link on this tutorial page.&lt;br /&gt;
&lt;br /&gt;
Please download and extract the file.&lt;br /&gt;
&lt;br /&gt;
|| The following '''code file''' is required to practice this tutorial.&lt;br /&gt;
&lt;br /&gt;
This file is provided in the '''Code Files''' link of this tutorial page.&lt;br /&gt;
&lt;br /&gt;
Please download and extract the file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Open pgAdmin 4'''&lt;br /&gt;
&lt;br /&gt;
|| I have opened '''pgAdmin4''' and connected to the '''PostgreSQL''' server.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| &lt;br /&gt;
|| Now let us create a database named '''Company'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Right click on '''Databases''' node.&lt;br /&gt;
&lt;br /&gt;
From the submenu select Create and then select Database.&lt;br /&gt;
Create database window opens.&lt;br /&gt;
Type database name: Company&lt;br /&gt;
Click Save at the bottom right corner.&lt;br /&gt;
|| Right-click on the '''Databases node'''.&lt;br /&gt;
From the submenu select '''Create''' and then select '''Database'''.&lt;br /&gt;
In the '''Create Database''' window, let us type the '''Database''' name as '''Company'''.&lt;br /&gt;
&lt;br /&gt;
Click the '''Save''' button at the bottom right corner.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Under the Database expand '''Schemas''' node, '''public''' node and '''Tables''' node.&lt;br /&gt;
|| Now let us expand the '''Schemas''' node, '''public''' node and then '''Tables''' node.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Right click on '''Tables''' node and select Query Tool.&lt;br /&gt;
Query window opens.&lt;br /&gt;
&lt;br /&gt;
|| Right click on '''Tables''' node and select the '''Query Tool''' option.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The '''Query''' window opens.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Type: &lt;br /&gt;
&lt;br /&gt;
'''CREATE TABLE department ('''&lt;br /&gt;
'''dept_id INT PRIMARY KEY,'''&lt;br /&gt;
'''dept_name VARCHAR(50)'''&lt;br /&gt;
''');'''&lt;br /&gt;
&lt;br /&gt;
Click on the '''execute query''' icon'''.'''&lt;br /&gt;
&lt;br /&gt;
|| Let me create a table named '''department'''.&lt;br /&gt;
Type this query in the query window.&lt;br /&gt;
Here '''department id''' is the '''primary key'''.&lt;br /&gt;
It uniquely identifies each department.&lt;br /&gt;
&lt;br /&gt;
Click on the '''execute query icon''' to execute the query.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Type:&lt;br /&gt;
&lt;br /&gt;
'''CREATE TABLE employee ('''&lt;br /&gt;
'''emp_id INT PRIMARY KEY,'''&lt;br /&gt;
'''emp_name VARCHAR(50),'''&lt;br /&gt;
'''salary INT,'''&lt;br /&gt;
'''dept_id INT'''&lt;br /&gt;
''');'''&lt;br /&gt;
&lt;br /&gt;
Click the '''Execute query icon.'''&lt;br /&gt;
&lt;br /&gt;
|| Now let us create a table named '''employee'''.&lt;br /&gt;
Type the following query.&lt;br /&gt;
In this query '''employee id''' is the '''primary key.'''&lt;br /&gt;
In this table '''department id''' is just a column.&lt;br /&gt;
There is no restriction on its values.&lt;br /&gt;
Click the '''Execute query icon''' to execute the query.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Point to the database and tables.&lt;br /&gt;
|| We have successfully created the database and tables.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Type:&lt;br /&gt;
'''INSERT INTO department VALUES'''&lt;br /&gt;
'''(1, 'HR'),'''&lt;br /&gt;
'''(2, 'IT'),'''&lt;br /&gt;
'''(3, 'Sales');'''&lt;br /&gt;
&lt;br /&gt;
Click on the '''execute query button'''.&lt;br /&gt;
&lt;br /&gt;
|| Now let us insert some data into the '''department''' table.&lt;br /&gt;
Now type the following query.&lt;br /&gt;
&lt;br /&gt;
Let me execute the query to see the output.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Type:&lt;br /&gt;
&lt;br /&gt;
'''SELECT * FROM department;'''&lt;br /&gt;
&lt;br /&gt;
Click on the '''execute query button**.&lt;br /&gt;
&lt;br /&gt;
|| We will now type this query.&lt;br /&gt;
Let us execute the query to see the created table.&lt;br /&gt;
Here is the '''department''' table with 3 records.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Type:&lt;br /&gt;
&lt;br /&gt;
'''INSERT INTO employee VALUES'''&lt;br /&gt;
'''(101, 'Ajay', 50000, 1),'''&lt;br /&gt;
'''(102, 'Neha', 60000, 2),'''&lt;br /&gt;
'''(103, 'Raj', 55000, 3),'''&lt;br /&gt;
'''(104, 'Simran', 65000, 10),'''&lt;br /&gt;
'''(105, 'Karan', 48000, 5);'''&lt;br /&gt;
&lt;br /&gt;
Click on the '''execute query button'''.&lt;br /&gt;
&lt;br /&gt;
|| Now let us insert some data into the '''employee''' table.&lt;br /&gt;
Type this query to insert the records in the '''employee''' table.&lt;br /&gt;
Let us execute the query and see the output.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Type:&lt;br /&gt;
&lt;br /&gt;
'''SELECT * FROM employee;'''&lt;br /&gt;
Click the '''Execute query icon.&lt;br /&gt;
&lt;br /&gt;
|| Now type this query.&lt;br /&gt;
&lt;br /&gt;
Let us execute the query and see the output.&lt;br /&gt;
Here is the employee table.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Highlight the '''dept id records 10 and 5 in the employee table.'''&lt;br /&gt;
&lt;br /&gt;
|| Observe that, dept id 10 and dept id 5 are not available in the department table.&lt;br /&gt;
However the database still allows the values.&lt;br /&gt;
This creates inconsistent data.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| &lt;br /&gt;
|| To prevent such issues, we use a foreign key constraint.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Type:'''&lt;br /&gt;
&lt;br /&gt;
'''DELETE FROM employee WHERE dept_id NOT IN (1,2,3);'''&lt;br /&gt;
&lt;br /&gt;
Click the '''Execute query icon.'''&lt;br /&gt;
&lt;br /&gt;
|| Let us first delete the inconsistent data from the '''employee''' table.&lt;br /&gt;
Type this query.&lt;br /&gt;
In this query the '''Delete''' keyword deletes records.&lt;br /&gt;
Let us execute the query.&lt;br /&gt;
The output shows the query returned successfully.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Type:&lt;br /&gt;
&lt;br /&gt;
'''SELECT * FROM employee;'''&lt;br /&gt;
&lt;br /&gt;
Click the '''Execute query icon.&lt;br /&gt;
&lt;br /&gt;
|| Let us type this query to see the updated table.&lt;br /&gt;
Let us execute the query.&lt;br /&gt;
The records with dept id 10 and dept id  5 are deleted from the '''employee''' table.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| &lt;br /&gt;
|| Now, let us learn about Foreign key.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 6&lt;br /&gt;
&lt;br /&gt;
What is a Foreign key?'''&lt;br /&gt;
&lt;br /&gt;
|| * A foreign key is a column that references a primary key in another table.&lt;br /&gt;
* It creates a relationship between two tables in a database.&lt;br /&gt;
* It ensures that the referenced value exists in the parent table.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 7&lt;br /&gt;
&lt;br /&gt;
Syntax of Foreign key&lt;br /&gt;
FOREIGN KEY (column_name) REFERENCES parent_table(column_name);'''&lt;br /&gt;
&lt;br /&gt;
|| This is the syntax of the Foreign key constraint.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| &lt;br /&gt;
|| Let’s add a Foreign key.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Type:&lt;br /&gt;
&lt;br /&gt;
'''ALTER TABLE employee'''&lt;br /&gt;
'''ADD CONSTRAINT fk_dept'''&lt;br /&gt;
'''FOREIGN KEY (dept_id) REFERENCES department(dept_id);'''&lt;br /&gt;
&lt;br /&gt;
Click the '''Execute query icon.'''&lt;br /&gt;
&lt;br /&gt;
|| Type the following query.&lt;br /&gt;
&lt;br /&gt;
This query adds a '''foreign key''' on dept id.&lt;br /&gt;
Each value must exist in the department table.&lt;br /&gt;
We will now execute the query.&lt;br /&gt;
Output shows '''Query''' returned successfully.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Type this command and execute:'''&lt;br /&gt;
&lt;br /&gt;
'''INSERT INTO employee'''&lt;br /&gt;
'''VALUES (105, 'Karan', 48000, 7);'''&lt;br /&gt;
&lt;br /&gt;
Click the '''Execute query icon.'''&lt;br /&gt;
&lt;br /&gt;
'''Point to the error.'''&lt;br /&gt;
&lt;br /&gt;
|| Now, let us insert an invalid department id.&lt;br /&gt;
Type the following query&lt;br /&gt;
Let us execute the query.&lt;br /&gt;
The result shows an error.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Type:&lt;br /&gt;
&lt;br /&gt;
INSERT INTO employee'''&lt;br /&gt;
'''VALUES'''&lt;br /&gt;
'''(104, 'Simran', 65000, 3),'''&lt;br /&gt;
'''(105, 'Karan', 48000, 2);'''&lt;br /&gt;
|| Type the following query.&lt;br /&gt;
&lt;br /&gt;
It inserts a valid record without issues.&lt;br /&gt;
&lt;br /&gt;
Now execute the query.&lt;br /&gt;
&lt;br /&gt;
A foreign key links two tables.&lt;br /&gt;
It ensures data integrity by preventing invalid entries.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Type:&lt;br /&gt;
&lt;br /&gt;
**SELECT * FROM employee;'''&lt;br /&gt;
&lt;br /&gt;
Click the '''Execute query icon.**&lt;br /&gt;
&lt;br /&gt;
|| Let us type this query to see the updated table.&lt;br /&gt;
Let us execute the query.&lt;br /&gt;
The records are now updated in the employee table.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 8'''&lt;br /&gt;
&lt;br /&gt;
'''Summary'''&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we have learnt about:&lt;br /&gt;
&lt;br /&gt;
*Foreign key constraint&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|| With this we come to the end of this tutorial.&lt;br /&gt;
Let us summarise&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 9'''&lt;br /&gt;
&lt;br /&gt;
'''Assignment'''&lt;br /&gt;
&lt;br /&gt;
'''As an assignment,'''&lt;br /&gt;
&lt;br /&gt;
'''Create a table named project with columns:&lt;br /&gt;
project_id, project_name, and dept_id.'''&lt;br /&gt;
'''Add a foreign key on dept_id referencing the department table.'''&lt;br /&gt;
'''Insert a valid record and execute the query.'''&lt;br /&gt;
'''Insert an invalid record and observe the error.'''&lt;br /&gt;
&lt;br /&gt;
|| We encourage you to try this assignment.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| '''Slide 10'''&lt;br /&gt;
&lt;br /&gt;
'''Thank you'''&lt;br /&gt;
&lt;br /&gt;
This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited SINE IIT Bombay.&lt;br /&gt;
&lt;br /&gt;
'''Thank you.'''&lt;br /&gt;
&lt;br /&gt;
|| Thank you for joining.&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>ANJALISATDIVE</name></author>	</entry>

	</feed>