Introduction to SQL

SQL Tutorial

🗄️ Introduction to SQL (Beginner-Friendly Guide)

SQL (Structured Query Language) is a standard language used to store, retrieve, manage, and manipulate data in relational databases.
It is essential for backend development, data analysis, and interviews.


1️⃣ What is SQL?

SQL is a query language used to communicate with a database.

With SQL, you can:

  • Create databases & tables

  • Insert, update, delete data

  • Retrieve data using queries

  • Control access & security


2️⃣ What is a Database?

A database is an organized collection of data stored in tables.

Example: students table

id name marks
1 Rahul 85
2 Ankit 90

✔ Rows = records
✔ Columns = fields


3️⃣ Why Learn SQL? ⭐

  • Used in almost every application

  • Required for backend & full-stack

  • Core skill for data analyst / data science

  • Extremely common in interviews

  • Works with many databases (MySQL, PostgreSQL, Oracle, SQL Server)


4️⃣ Types of SQL Commands ⭐

SQL commands are grouped into 5 main categories:


🔹 1. DDL (Data Definition Language)

Used to define database structure.

Command Purpose
CREATE Create table/database
ALTER Modify table
DROP Delete table/database
TRUNCATE Remove all records
CREATE TABLE students (
id INT,
name VARCHAR(50),
marks INT
);

🔹 2. DML (Data Manipulation Language)

Used to manipulate data.

Command Purpose
INSERT Add data
UPDATE Modify data
DELETE Remove data
INSERT INTO students VALUES (1, 'Rahul', 85);

🔹 3. DQL (Data Query Language)

Used to fetch data.

Command Purpose
SELECT Retrieve data
SELECT * FROM students;

🔹 4. DCL (Data Control Language)

Used to control access.

Command Purpose
GRANT Give permission
REVOKE Remove permission

🔹 5. TCL (Transaction Control Language)

Used to manage transactions.

Command Purpose
COMMIT Save changes
ROLLBACK Undo changes
SAVEPOINT Create rollback point

5️⃣ Basic SQL Syntax Rules ⭐

  • SQL keywords are NOT case-sensitive

    SELECT * FROM students;
    select * from students;
  • End statements with semicolon ;

  • Strings are written in single quotes

    'Rahul'

6️⃣ Common SQL Data Types 🔢

Type Description
INT Integer number
FLOAT Decimal number
VARCHAR(n) String
DATE Date
BOOLEAN True / False

7️⃣ Basic SQL Queries (Examples) ⭐

Select specific columns

SELECT name, marks FROM students;

Filter data using WHERE

SELECT * FROM students WHERE marks > 80;

Sort data using ORDER BY

SELECT * FROM students ORDER BY marks DESC;

8️⃣ SQL vs NoSQL (Quick Comparison)

SQL NoSQL
Table-based Document / Key-Value
Fixed schema Flexible schema
Structured data Unstructured data
Uses SQL Uses APIs / JSON

9️⃣ Where SQL is Used? 🔥

  • Banking systems

  • E-commerce websites

  • Hospital management

  • School/college systems

  • Backend servers

  • Data analytics & reporting


🔟 Common Beginner Mistakes ❌

❌ Forgetting WHERE condition in DELETE
❌ Using double quotes instead of single quotes
❌ Confusing DELETE and TRUNCATE
❌ Not understanding primary keys


📌 Interview Questions (Must Prepare)

  1. What is SQL?

  2. Difference between SQL and DBMS?

  3. What are DDL, DML, DQL?

  4. What is a primary key?

  5. Difference between DELETE and TRUNCATE?

  6. What is SELECT *?


✅ Summary

✔ SQL is used to interact with databases
✔ Data is stored in tables (rows & columns)
✔ SQL commands are grouped into DDL, DML, DQL, DCL, TCL
SELECT is the most used command
✔ Essential for backend, data, and interviews

You may also like...