Introduction to SQL
🗄️ 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 |
🔹 2. DML (Data Manipulation Language)
Used to manipulate data.
| Command | Purpose |
|---|---|
INSERT |
Add data |
UPDATE |
Modify data |
DELETE |
Remove data |
🔹 3. DQL (Data Query Language)
Used to fetch data.
| Command | Purpose |
|---|---|
SELECT |
Retrieve data |
🔹 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
-
End statements with semicolon
; -
Strings are written in single quotes
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
Filter data using WHERE
Sort data using ORDER BY
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)
-
What is SQL?
-
Difference between SQL and DBMS?
-
What are DDL, DML, DQL?
-
What is a primary key?
-
Difference between
DELETEandTRUNCATE? -
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
