SQL (Structured Query Language) is a declarative language used to define, query, and manipulate data in relational databases.
Interview-friendly one-liner:
SQL is a declarative language for working with relational data: you describe what data you want, not how to get it.
1. What SQL is used for
SQL covers four main areas:
1️⃣ Data Querying (DQL)
Retrieve data.
SELECT id, name
FROM users
WHERE active = true;
2️⃣ Data Manipulation (DML)
Insert, update, delete data.
INSERT INTO users (name) VALUES ('Stanley');
UPDATE users SET active = false WHERE id = 10;
DELETE FROM users WHERE id = 10;
3️⃣ Schema Definition (DDL)
Define and change structure.
CREATE TABLE users (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL
);
ALTER TABLE users ADD COLUMN email TEXT;
4️⃣ Access Control (DCL)
Permissions and security.
GRANT SELECT ON users TO reporting_user;
2. Declarative vs imperative (important for interviews)
- SQL is declarative
- You describe what result you want
- The query planner decides how to execute it
SELECT * FROM orders WHERE price > 100;
You don’t say:
- which index to use
- how to scan rows
- in what order to join tables
➡️ That’s handled by the database engine.
3. SQL works with relational data
Key concepts:
- Tables
- Rows
- Columns
- Primary keys
- Foreign keys
- Relations
Example:
orders.user_id → users.id
This enforces data integrity.
4. SQL is standardized, but dialects differ
SQL has a standard, but every DB has its own dialect:
| Database | Notes |
|---|---|
| PostgreSQL | Very close to standard, rich features |
| MySQL | Looser typing, popular |
| Oracle | Enterprise-focused |
| SQL Server | Microsoft ecosystem |
Same query may behave slightly differently across DBs.
5. SQL vs NoSQL (quick contrast)
| SQL | NoSQL |
|---|---|
| Relational | Non-relational |
| Schema-based | Often schema-less |
| ACID transactions | Often eventual consistency |
| Strong joins | Limited / no joins |
➡️ SQL shines when consistency and relations matter.
6. How to answer in an interview (perfect short answer)
SQL is a declarative language for working with relational databases.
It’s used to query data, modify records, define schemas, and manage access.
You specify what result you want, and the database decides how to execute it efficiently.
Common interview traps ⚠️
- ❌ “SQL is a programming language like Java”
→ It’s a query language, not general-purpose - ❌ “SQL is the same everywhere”
→ Dialects matter - ❌ Ignoring transactions and ACID