What is SQL? Command Types
SQL = Structured Query Language
- Pronounced "S-Q-L" or "sequel"
- The standard language for working with relational databases (ANSI/ISO standard since 1986)
- Declarative: you describe what you want, and the database works out how to get it
SELECT name FROM users WHERE city = 'Pokhara';
You don't write loops — the database's query planner chooses the fastest way.
The 5 groups of SQL commands
| Group | Meaning | Commands |
|---|---|---|
| DDL | Data Definition – structure | CREATE, ALTER, DROP, TRUNCATE |
| DML | Data Manipulation – change rows | INSERT, UPDATE, DELETE |
| DQL | Data Query – read | SELECT |
| DCL | Data Control – permissions | GRANT, REVOKE |
| TCL | Transaction Control | BEGIN, COMMIT, ROLLBACK, SAVEPOINT |
Syntax basics
- Statements end with a semicolon
; - Keywords are case-insensitive:
SELECT=select. By convention we write keywords in UPPERCASE. - Unquoted identifiers (table/column names) are folded to lowercase. Use snake_case:
monthly_budget. - Strings use single quotes:
'Kathmandu'. Double quotes are for identifiers:"Order". - Comments:
-- single lineand/* multi-line */ - Whitespace and line breaks don't matter — format for readability
SQL dialects
Every database adds its own extras: PostgreSQL (ILIKE, RETURNING, JSONB), MySQL (AUTO_INCREMENT), SQL Server (TOP), SQLite. The core (SELECT, JOIN, GROUP BY…) is the same everywhere.
Example
-- DDL: define structure
CREATE TABLE goals (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
title TEXT NOT NULL,
target NUMERIC(10,2)
);
-- DML: change data
INSERT INTO goals (title, target) VALUES ('New phone', 45000);
UPDATE goals SET target = 50000 WHERE title = 'New phone';
-- DQL: read data
SELECT * FROM goals;
-- TCL: group changes into one transaction
BEGIN;
DELETE FROM goals;
ROLLBACK; -- undo! the row is still there
SELECT count(*) FROM goals; -- 1
-- DCL: permissions (who can read the table)
-- GRANT SELECT ON goals TO reporting_user;
/* Keywords are case-insensitive,
but UPPERCASE keywords are easier to read */
select title from goals;
DROP TABLE goals;