Reference
SQL Reserved Keywords Complete SQL keyword reference organized by purpose. If your table or column name matches a reserved keyword, quote it ("name" in PostgreSQL, `name` in MySQL, [name] in SQL Server) to avoid syntax errors. Format queries with the SQL Formatter .
Data Query (DQL) Joins Data Manipulation (DML) Data Definition (DDL) Constraints Operators & Predicates Aggregate Functions Window Functions Transaction Control Access Control (DCL) Common Table Expressions & Subqueries Data Types (cross-database) Data Query (DQL) Keyword Description SELECT Retrieve rows from one or more tables FROM Specify the source table(s) WHERE Filter rows by condition GROUP BY Group rows sharing a column value HAVING Filter groups after aggregation ORDER BY Sort results by column(s) LIMIT Restrict number of rows returned (MySQL, PostgreSQL, SQLite) OFFSET Skip rows before returning results FETCH Restrict rows (SQL standard, SQL Server) DISTINCT Remove duplicate rows from results ALL Include duplicates (default) TOP Restrict number of rows (SQL Server) UNION Combine results of two queries (deduplicated) UNION ALL Combine results of two queries (with duplicates) INTERSECT Rows present in both queries EXCEPT Rows in first query but not second (MINUS in Oracle)
Joins Keyword Description JOIN Combine rows from two tables INNER JOIN Rows matching in both tables LEFT JOIN All left rows, matched right rows (NULLs for no match) RIGHT JOIN All right rows, matched left rows FULL OUTER JOIN All rows from both tables CROSS JOIN Cartesian product of both tables NATURAL JOIN Join on columns with the same name ON Specify the join condition USING Join on a shared column name
Data Manipulation (DML) Keyword Description INSERT INTO Add new rows to a table VALUES Specify literal row data for INSERT UPDATE Modify existing rows SET Assign new column values in UPDATE DELETE Remove rows from a table MERGE Insert, update, or delete in a single statement (UPSERT) REPLACE Insert or replace existing row (MySQL) TRUNCATE Remove all rows (faster than DELETE, no rollback) RETURNING Return affected rows (PostgreSQL, SQLite 3.35+)
Data Definition (DDL) Keyword Description CREATE Create a database object (TABLE, INDEX, VIEW, etc.) ALTER Modify an existing object DROP Remove an object permanently TABLE A structured set of rows and columns VIEW A named query stored as a virtual table INDEX A data structure to speed lookups SEQUENCE An auto-incrementing number generator SCHEMA A namespace for database objects DATABASE A collection of schemas and objects COLUMN A field in a table ADD Add a column or constraint (ALTER TABLE) RENAME Rename a table or column IF EXISTS Avoid error if object is missing (DROP) IF NOT EXISTS Avoid error if object already exists (CREATE) TEMPORARY Create a session-scoped table
Constraints Keyword Description PRIMARY KEY Uniquely identify each row FOREIGN KEY Reference a row in another table REFERENCES Specify the target of a foreign key UNIQUE Prevent duplicate values in a column NOT NULL Disallow NULL values CHECK Enforce a boolean expression on column values DEFAULT Provide a fallback value when none is given CONSTRAINT Name a table constraint explicitly AUTO_INCREMENT Auto-generate sequential IDs (MySQL) SERIAL Auto-incrementing integer column (PostgreSQL) AUTOINCREMENT Strict auto-increment (SQLite) IDENTITY Auto-incrementing column (SQL Server, SQL standard) CASCADE Propagate deletes/updates to child rows RESTRICT Prevent delete/update if child rows exist
Operators & Predicates Keyword Description AND Logical AND OR Logical OR NOT Logical negation IN Match any value in a list or subquery BETWEEN Match a range (inclusive) LIKE Pattern match with % and _ wildcards ILIKE Case-insensitive LIKE (PostgreSQL) IS NULL Test for NULL IS NOT NULL Test for non-NULL EXISTS True if subquery returns any row ANY Compare to any value from a subquery SOME Synonym for ANY CASE Conditional expression (CASE WHEN ... THEN ... ELSE ... END) WHEN Branch inside a CASE expression THEN Result for a CASE WHEN branch ELSE Default CASE result END Close a CASE or BEGIN block AS Alias a column or table CAST Convert a value to a different type COALESCE Return first non-NULL argument NULLIF Return NULL if two values are equal
Aggregate Functions Keyword Description COUNT Number of rows SUM Total of numeric values AVG Average of numeric values MIN Smallest value MAX Largest value STRING_AGG Concatenate strings with delimiter (PostgreSQL, SQL Server) GROUP_CONCAT Concatenate strings (MySQL, SQLite) ARRAY_AGG Collect values into an array (PostgreSQL)
Window Functions Keyword Description OVER Define a window for the function PARTITION BY Divide rows into groups within a window ROW_NUMBER Sequential integer per partition RANK Rank with gaps on ties DENSE_RANK Rank without gaps on ties NTILE Distribute rows into N buckets LAG Value from a previous row LEAD Value from a following row FIRST_VALUE First value in the window frame LAST_VALUE Last value in the window frame ROWS Physical row-based window frame RANGE Logical value-based window frame
Transaction Control Keyword Description BEGIN Start a transaction COMMIT Save all changes since BEGIN ROLLBACK Undo all changes since BEGIN SAVEPOINT Create a named restore point RELEASE Remove a savepoint LOCK Acquire a table or row lock
Access Control (DCL) Keyword Description GRANT Give permissions to a user or role REVOKE Remove permissions from a user or role ROLE A named set of permissions USER A database account
Common Table Expressions & Subqueries Keyword Description WITH Define a Common Table Expression (CTE) RECURSIVE Allow a CTE to reference itself LATERAL Subquery that references preceding FROM items (PostgreSQL)
Data Types (cross-database) Keyword Description INTEGER Whole number (INT is a common alias) BIGINT 64-bit integer SMALLINT 16-bit integer DECIMAL Exact fixed-point number (NUMERIC is equivalent) FLOAT Approximate floating-point number DOUBLE PRECISION 64-bit floating-point BOOLEAN True or false VARCHAR Variable-length string CHAR Fixed-length string TEXT Unlimited-length string DATE Calendar date (year, month, day) TIME Time of day TIMESTAMP Date and time INTERVAL Time span BLOB Binary large object JSON JSON data (MySQL, PostgreSQL) JSONB Binary JSON with indexing (PostgreSQL) UUID Universally unique identifier (PostgreSQL) ARRAY Array of values (PostgreSQL)
Format your SQL Paste raw SQL and get clean, consistently indented output with keyword highlighting.
Open SQL Formatter