SQL Server

Difference between Primary Key and Foreign Key

Difference between Primary Key and Foreign Key

A primary key is used to ensure data in the specific column is unique. It is a column that cannot have NULL values. It is either an existing table column or a column that is specifically generated by the database according to a defined sequence.

Difference between primary key and foreign key
Difference between primary key and foreign key

What is Primary key:

Example: Refer to the image above:
STUD_NO, as well as STUD_PHONE both, are candidate keys for relation STUDENT but STUD_NO can be chosen as the primary key (only one out of many candidate keys).

What is a Foriegn key:

Example: Refer to the above image
STUD_NO in STUDENT_COURSE is a foreign key to STUD_NO in STUDENT relation.… Continue Reading

SQL Sample Database

SQL Sample Database

In the coming articles, we will be using our sample database which is an HR database. It has multiple seven tables which will be interlinked to get answered our question.

The description of tables are as mentioned below

The jobs table stores the job data including job title and salary range.

The dependents table stores the employee’s dependents.

The employees table stores the data of employees.

The departments table stores department data.

The regions table stores the data of regions such as Asia, Europe, America, and the Middle East and Africa. The countries are grouped into regions.

The locations table stores the location of the departments of the company.

The countries table stores the data of countries where … Continue Reading