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

What is SQL

Introduction to SQL language

SQL is a programming language that is used to manage data stored in a relational database management system (RDBMS).

SQL pronounced as /ˈɛs kjuː ˈɛl/ or /ˈsiːkwəl/. SQL full form is Structured Query Language.

SQL has three components:

  • Data Defination Language (DDL): The data definition language deals with the schema/Table/View creation and modification like, CREATE TABLE statement allows us to create a new table in the database and the ALTER TABLE statement helps in changing the structure of an existing table.
  • Data Manupulation Language(DML): The data manipulation language helps to query data such as the SELECT statement and to update the data such as INSERTUPDATE, and DELETE statements.
  • Data Control Language (DDL): The
Continue Reading