What is SQL?
SQL (Structured Query Language) is a language used to store, retrieve, update, delete, and
manage data in a database.
It works with databases like:
• MySQL
• SQL Server
• PostgreSQL
• Oracle
• SQLite
• MariaDB
Core SQL Commands (Think of them as categories)
DQL – Data Query Language (for fetching data)
Used to read or retrieve data.
• SELECT
Example:
SELECT * FROM employees;
DML – Data Manipulation Language (for modifying data)
Used to insert, update, delete records.
• INSERT
• UPDATE
• DELETE
Examples:
INSERT INTO employees (name, salary) VALUES ('John', 50000);
UPDATE employees SET salary = 60000 WHERE name = 'John';
DELETE FROM employees WHERE name = 'John';
DDL – Data Definition Language (for creating structures)
Used to create or modify tables, databases, indexes, etc.
• CREATE
• ALTER
• DROP
• TRUNCATE
Examples:
CREATE TABLE employees (
id INT,
name VARCHAR(100),
salary INT
);
ALTER TABLE employees ADD COLUMN age INT;
DROP TABLE employees;
DCL – Data Control Language (permissions/security)
Controlling access to the database.
• GRANT
• REVOKE
Example:
GRANT SELECT ON employees TO user1;
TCL – Transaction Control Language
Used to manage transactions.
• COMMIT
• ROLLBACK
• SAVEPOINT
Example:
BEGIN;
UPDATE accounts SET balance = balance - 1000 WHERE id = 1;
UPDATE accounts SET balance = balance + 1000 WHERE id = 2;
COMMIT;
Most Commonly Used SQL Syntax
✔ 1. Selecting data
SELECT column1, column2 FROM table_name;
✔ 2. Filtering rows
SELECT * FROM employees WHERE salary > 50000;
✔ 3. Sorting data
SELECT * FROM employees ORDER BY salary ASC;
✔ 4. Grouping data
SELECT department, COUNT(*)
FROM employees
GROUP BY department;
✔ 5. Joining tables
SELECT [Link], departments.dept_name
FROM employees
JOIN departments ON employees.dept_id = [Link];
Super Simple Analogy
A database is like an Excel file with many sheets (tables).
SQL is the language you use to ask questions about the data, modify it, or design new
sheets.
If you want, I can also provide:
SQL cheat sheet
Practice questions with answers
Real-world examples (banking, e-commerce, HR, etc.)
Just tell me!