SQL · Module 1 · Lesson 31 min read

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
ini
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

GroupMeaningCommands
DDLData Definition – structureCREATE, ALTER, DROP, TRUNCATE
DMLData Manipulation – change rowsINSERT, UPDATE, DELETE
DQLData Query – readSELECT
DCLData Control – permissionsGRANT, REVOKE
TCLTransaction ControlBEGIN, 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 line and /* 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

SQL
-- 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;