What is a Foreign Key in SQL|| SQL tutorial for beginners in Hindi Educate Cube

  Рет қаралды 8

Educate Cube

Educate Cube

19 күн бұрын

What is a Foreign Key in SQL?
#foreignkey #sqltutorialforbeginners #databasemanagement
Linkedin Group: / 14478259
Hello everyone, welcome to Educate Cube. Today, we will learn about foreign keys and what they are. In relational databases, a foreign key is a column or set of columns in a table that refers to the primary key or unique key in another table. Let's understand this with an example. Imagine we have two tables: an employee table and a sales table. In the employee table, we have an employee ID, and in the sales table, we also have an employee ID. If you look at the employee table, the employee ID never repeats, which means it is our primary key. In the sales table, we have the same column, but here, it contains duplicate values that function as our foreign key. The purpose of a foreign key is to establish a link or relationship between the tables. This relationship is known as referential integrity. It helps maintain the quality and authenticity of the data. It is crucial for maintaining consistency and accuracy of data across tables.
Now, let's see how to define a foreign key in SQL Server Management Studio. Let's say we have a table. We will create a table by pressing F5. I will also ingest some data into the employee table. To ingest data, we go to the database, click on Educate Cube, and then on Tasks. We select the option to import data, specify the source file, and proceed to the next step. We specify the destination and make sure all steps are marked correctly. If there is an error, for example, in the joining date's data type, we need to resolve it. Once we check the data, we can see that it has been ingested successfully. We refresh, and our table is applied.
Next, I will ingest another table. This is an example table. I will create this table and ingest some data into it. We will specify the source file and destination. We have explained how to ingest data in our previous videos, so if you are not familiar, please refer to them for detailed steps. Now, our sales data is inserted, and we refresh.
To create a foreign key, we right-click on the table, select Relationships, and click on Table and Column Specification. The system automatically selects the FK Sales name, as FK stands for Foreign Key. We will link the sales table to the employee table using the employee ID. In the sales table, we will select the employee ID, and this establishes our foreign key. We click OK and confirm. To verify, we can go to the Database Diagram.
Here, we add the employee and sales tables. You will see a link indicating the primary key in the employee table and the foreign key in the sales table. This is how we check the foreign key.
That's all for this video. I hope you liked it. Thank you for watching Educate Cube. Please like, share, and subscribe to our channel.

Пікірлер
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 120 М.
Happy 4th of July 😂
00:12
Pink Shirt Girl
Рет қаралды 61 МЛН
Этот Пёс Кое-Что Наделал 😳
00:31
Глеб Рандалайнен
Рет қаралды 4,2 МЛН
Despicable Me Fart Blaster
00:51
_vector_
Рет қаралды 19 МЛН
Can You Draw A PERFECTLY Dotted Line?
00:55
Stokes Twins
Рет қаралды 114 МЛН
Why I Chose Rust Over Zig
33:18
ThePrimeTime
Рет қаралды 27 М.
How do SQL Indexes Work
12:12
kudvenkat
Рет қаралды 589 М.
Happy 4th of July 😂
00:12
Pink Shirt Girl
Рет қаралды 61 МЛН