Software Development, Be a Better Programmer, Programming, System Design

SQL Full Course Part 1 | What is SQL? Basics to Intermediate | Installation Guide | Interview Preparation

This complete SQL article will teach you SQL from scratch , covering everything — SQL meaning, installation setup (Windows, Mac, Linux), real-world SQL examples.

Introduction

Imagine you have 10,000 photos saved on your computer.
If they are saved randomly, how will you find one specific photo?
It will take a lot of time, right?

Now think — if you keep all photos arranged year-wise, month-wise, event-wise, you can find any photo easily.

Similarly, computers also need a system to organize, store, and manage huge amounts of information.
This system is called a Database.
And the language used to talk to a database is called SQL.


What is SQL?

SQL stands for Structured Query Language.
It is used to create, store, modify, and retrieve data in a database.

In simple words:
SQL = Language to manage and talk to your database.

You can:

  • Create new databases and tables
  • Insert new data
  • Update existing data
  • Delete data
  • Search and retrieve data

Why do we need SQL?

  • To store data safely.
  • To find any information fast.
  • To manage millions of records easily.
  • To protect important data with security rules.

Real-life example:
When you log into Instagram, SQL fetches your profile details from their database instantly!


History of SQL

  • 1970 — E.F. Codd introduced the concept of Relational Databases.
  • 1974 — SQL was developed by Donald D. Chamberlin and Raymond F. Boyce at IBM.
  • Originally named SEQUEL (Structured English Query Language).
  • Later changed to SQL.
  • Now SQL is a standard language used by almost every organization.

How to Install SQL (MySQL Database)

We will install MySQL, one of the most popular free database systems.

Step-by-Step:

  1. Visit website
  2. Download MySQL Community Server.
  3. Install by clicking Next → Next → Next.
  4. Set a password during setup (remember it!).
  5. Install MySQL Workbench to write queries easily.

Now you’re ready to use SQL!


Components of SQL

SQL is divided into different parts:

LanguageMeaningCommands
DDLData Definition LanguageCREATE, ALTER, DROP
DMLData Manipulation LanguageINSERT, UPDATE, DELETE
DQLData Query LanguageSELECT
DCLData Control LanguageGRANT, REVOKE
TCLTransaction Control LanguageCOMMIT, ROLLBACK

Important SQL Commands

DDL

  1. CREATE — To create a new database or table.
-- Create a new Database
CREATE DATABASE School;

-- Create a new Table
CREATE TABLE Students (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT
);

Explanation:

  • CREATE DATABASE creates a new database.
  • CREATE TABLE creates a table with columns ID, Name, and Age.

  1. ALTER — To modify existing table structure.
-- Add a new column to Students table
ALTER TABLE Students ADD Email VARCHAR(100);

Explanation:
We are adding a new column called Email to the existing Students table.


  1. DROP — To delete a database or table.
-- Delete the Students table
DROP TABLE Students;

Warning:
DROP permanently deletes data.


DML Commands

  1. INSERT — To add new data.
-- Insert a record
INSERT INTO Students (ID, Name, Age) VALUES (1, 'John', 18);
  1. UPDATE — To modify existing data.
-- Update John's age
UPDATE Students SET Age = 19 WHERE ID = 1;
  1. DELETE — To remove data.
-- Delete John's record
DELETE FROM Students WHERE ID = 1;

DQL Command

  1. SELECT — To retrieve data.
-- View all students
SELECT * FROM Students;

-- View only names of students
SELECT Name FROM Students;

SQL Syntax

  • SQL keywords are usually written in CAPITAL letters.
  • Always use a semicolon (;) to end queries.
  • Use WHERE clause carefully while updating or deleting data.
  • Practice indentation for better readability.

Example:

SELECT Name
FROM Students
WHERE Age > 18;

Basic Interview Questions and Answers


Q1. What is SQL?

Answer:
SQL is a language used to manage and manipulate data in relational databases.


Q2. What is the difference between SQL and MySQL?

Answer:

  • SQL is a language.
  • MySQL is a database management system (software) that uses SQL to manage data.

Q3. What is a Primary Key?

Answer:
A Primary Key is a unique identifier for each record in a table.
Example:

CREATE TABLE Students (
ID INT PRIMARY KEY,
Name VARCHAR(50)
);

Here, ID is the primary key — no two students can have the same ID.


Q4. What is a Foreign Key?

Answer:
A Foreign Key is a field that creates a relationship between two tables.

Example:

CREATE TABLE Courses (
CourseID INT PRIMARY KEY,
CourseName VARCHAR(50)
);

CREATE TABLE StudentCourses (
StudentID INT,
CourseID INT,
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);

Here, CourseID in StudentCourses is a foreign key linking it to the Courses table.


Q5. What are Constraints in SQL?

Answer:
Constraints are rules applied to table columns to protect data.

Common constraints:

  • NOT NULL — Cannot leave value empty.
  • UNIQUE — All values must be different.
  • PRIMARY KEY — Unique + Not Null.
  • FOREIGN KEY — Connects two tables.
  • CHECK — Limit values.
  • DEFAULT — Set a default value.

Example:

CREATE TABLE Students (
ID INT PRIMARY KEY,
Age INT CHECK (Age >= 18)
);

Here, only students aged 18 or above are allowed.


Mini Project

Let’s build a small project:

Step 1: Create Database

CREATE DATABASE Company;

Step 2: Create Table

CREATE TABLE Employees (
EmpID INT PRIMARY KEY,
Name VARCHAR(50),
Department VARCHAR(30),
Salary INT
);

Step 3: Insert Data

INSERT INTO Employees (EmpID, Name, Department, Salary) VALUES 
(1, 'Alice', 'HR', 40000),
(2, 'Bob', 'Finance', 55000),
(3, 'Charlie', 'IT', 60000);

Step 4: Select Data

-- View all Employees
SELECT * FROM Employees;

Step 5: Update Data

-- Increase salary of Bob
UPDATE Employees
SET Salary = 58000
WHERE Name = 'Bob';

Step 6: Delete Data

-- Remove Charlie from Employees
DELETE FROM Employees
WHERE Name = 'Charlie';

SQL is not difficult — it’s just like giving small English commands to the computer.
The more you practice, the more natural it becomes.

  • Understand the basic commands.
  • Try small projects.
  • Solve practice exercises.
  • Prepare interview questions properly.

Mastering SQL = Big step towards IT jobs!

2 thoughts on “SQL Full Course Part 1 | What is SQL? Basics to Intermediate | Installation Guide | Interview Preparation

Leave a Reply

Your email address will not be published. Required fields are marked *