Skip to the workspace
Pebellslearn by building
Basic SQL Syntax  ›  Lesson

SQL Keywords and the Shape of a Statement

SQL Keywords 12 minKeywords are reserved words that mark each clause of a SQL statement, and the clauses of a query are always written in a fixed order.

sql / SQL Keywords and the Shape of a Statement

Explore each scene at your own pace.

01 · The rule

The rule

SQL Keywords and the Shape of a Statement

Keywords are reserved words that mark each clause of a SQL statement, and the clauses of a query are always written in a fixed order.

Read a query by clause and distinguish language keywords from chosen identifiers.

The first time you read a real query it can look like a wall of capital letters. It is far less random than it looks: a handful of reserved words mark where each part of the statement begins, and they always appear in the same order. Learn the order once and every query becomes readable.

The rule

Keywords are SQL's grammar; everything else is a name you chose.

A keyword is a word with a fixed meaning to the database: SELECT, FROM, WHERE, CREATE, TABLE, ORDER, BY. Everything else in a statement is an identifier (a table or column name you created) or a value (like 'Pune' or 42).

SELECT name, city        -- keyword, then column names
FROM customers           -- keyword, then a table name
WHERE city = 'Pune'      -- keyword, then a condition
ORDER BY name;           -- keywords, then a column; ; ends the statement

A few rules follow from this:

  • Keywords are case-insensitive. select, SELECT and Select all work. Writing them in capitals is a convention that makes your own names stand out.
  • A statement ends with a semicolon. Some tools let you skip it for a single statement, but it is required to separate several.
  • Reserved words make poor names. A table called order clashes with the keyword ORDER, which is one reason tables are often plural, like orders.
  • Text values go in single quotes: 'Pune'. Double quotes, in standard SQL, are for identifiers.

Keywords also come in families by job. DDL (data definition) shapes tables: CREATE, ALTER, DROP, TRUNCATE. DML (data manipulation) works with rows: SELECT, INSERT, UPDATE, DELETE. DCL controls access: GRANT, REVOKE. TCL controls transactions: COMMIT, ROLLBACK.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.