SQLSQL Syntax Basics

SQL Syntax Basics

Before diving into writing real queries, it helps to get comfortable with a handful of general conventions that apply across nearly every SQL statement you’ll ever write. None of these rules are difficult, but getting them right early will save you confusing errors later — and following the community conventions will make your SQL much easier for other people (and future you) to read.

Keywords: case-insensitive, but conventionally UPPERCASE
SQL keywords like SELECT, FROM, WHERE, and INSERT are case-insensitive — select, Select, and SELECT all work identically. However, the overwhelming convention across the SQL community is to write keywords in **UPPERCASE**, which makes it visually easy to separate SQL’s structural vocabulary from your own table and column names at a glance.

Same query, two styles

SQL
-- Works, but hard to scan
select id, name from customers where country = 'Canada';

-- Conventional and easier to read
SELECT id, name FROM customers WHERE country = 'Canada';
Identifiers: typically lowercase
Table names and column names — collectively called *identifiers* — are also generally case-insensitive in most databases (with some nuance depending on the specific system and quoting), but the strong community convention is to write them in **lowercase**, usually with underscores separating words (snake_case), such as first_name or order_items. Combining UPPERCASE keywords with lowercase identifiers gives you SQL that reads clearly at a glance:

UPPERCASE keywords, lowercase snake_case identifiers

SQL
SELECT first_name, last_name
FROM employees
WHERE department_id = 4;
Statements end with a semicolon
Every SQL statement should end with a semicolon (;). Most database tools will run a single statement without it, but the semicolon becomes essential the moment you write multiple statements together — it’s how the database knows where one statement ends and the next begins.

Multiple statements need semicolons to separate them

SQL
INSERT INTO employees (name) VALUES ('Jane Doe');
UPDATE employees SET department_id = 4 WHERE name = 'Jane Doe';
String literals use single quotes
In standard SQL, text values (string literals) are wrapped in **single quotes**, like 'Canada' or '2024-01-01'.
Double quotes mean something different in SQL
If you’re coming from a language like JavaScript or Python, where single and double quotes are usually interchangeable for strings, watch out — in standard SQL they are **not** the same thing. Double quotes are reserved for quoting *identifiers* (table or column names), typically only needed when a name contains spaces, special characters, or clashes with a reserved keyword. Writing WHERE country = "Canada" instead of WHERE country = 'Canada' is one of the most common beginner mistakes, and depending on the database it may throw an error or silently do something you didn’t intend.

Single quotes for values, double quotes for special identifiers

SQL
-- Correct: single quotes for a string value
SELECT * FROM customers WHERE country = 'Canada';

-- Double quotes are for identifiers, e.g. a column name with a space
SELECT "first name" FROM legacy_customers;
Whitespace and formatting are flexible
SQL does not care about extra spaces, tabs, or line breaks between keywords — they’re purely for human readability. A query can be written entirely on one line or spread across many; both run identically. Most developers format longer queries across multiple lines, with each major clause (SELECT, FROM, WHERE, and so on) starting on its own line, purely to make the query easier for humans to read and debug.
  • Consistent formatting matters far more for humans than for the database

  • Most teams adopt a shared style guide so queries look familiar across a codebase

  • Many editors and tools include a SQL formatter that can auto-apply consistent style for you