SQL — Primary key Vs Foreign Key
As we know that relationship between two or more tables in SQL Server is the basic concept of any relational database. For an example. a family always starts with Parent and Children relationship, same as is a database always starts with product-item or customers-regions relationship.
So, we will try to understand that how can we differentiate a relationship between two or more data tables in a database. You can suppose that Parent equals to Primary key and Children equal to Foreign key in a database.
In the above diagram, you can see the Primary Key and Foreign Key relationship between Students, Enrollments and Classes data tables.
In Students data table, Student ID is the primary key and it is establishing a relationship with Enrollments tables and acts as a Foreign key.
In Classes data table, Class ID is the primary key and it is establishing a relationship with Enrollments tables and acts as a Foreign key.
Primary Key — In a database, a table can have only one primary key which cannot have a NULL value. It always represents a clustered index in a database table and helps to organize the sequence of clustered index.
Primary key can be related to another tables as a Foreign Key and you can apply Auto Increment value for a Primary key but auto increment is not…