Skip to content

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)

KeywordDescription
SELECTRetrieve rows from one or more tables
FROMSpecify the source table(s)
WHEREFilter rows by condition
GROUP BYGroup rows sharing a column value
HAVINGFilter groups after aggregation
ORDER BYSort results by column(s)
LIMITRestrict number of rows returned (MySQL, PostgreSQL, SQLite)
OFFSETSkip rows before returning results
FETCHRestrict rows (SQL standard, SQL Server)
DISTINCTRemove duplicate rows from results
ALLInclude duplicates (default)
TOPRestrict number of rows (SQL Server)
UNIONCombine results of two queries (deduplicated)
UNION ALLCombine results of two queries (with duplicates)
INTERSECTRows present in both queries
EXCEPTRows in first query but not second (MINUS in Oracle)

Joins

KeywordDescription
JOINCombine rows from two tables
INNER JOINRows matching in both tables
LEFT JOINAll left rows, matched right rows (NULLs for no match)
RIGHT JOINAll right rows, matched left rows
FULL OUTER JOINAll rows from both tables
CROSS JOINCartesian product of both tables
NATURAL JOINJoin on columns with the same name
ONSpecify the join condition
USINGJoin on a shared column name

Data Manipulation (DML)

KeywordDescription
INSERT INTOAdd new rows to a table
VALUESSpecify literal row data for INSERT
UPDATEModify existing rows
SETAssign new column values in UPDATE
DELETERemove rows from a table
MERGEInsert, update, or delete in a single statement (UPSERT)
REPLACEInsert or replace existing row (MySQL)
TRUNCATERemove all rows (faster than DELETE, no rollback)
RETURNINGReturn affected rows (PostgreSQL, SQLite 3.35+)

Data Definition (DDL)

KeywordDescription
CREATECreate a database object (TABLE, INDEX, VIEW, etc.)
ALTERModify an existing object
DROPRemove an object permanently
TABLEA structured set of rows and columns
VIEWA named query stored as a virtual table
INDEXA data structure to speed lookups
SEQUENCEAn auto-incrementing number generator
SCHEMAA namespace for database objects
DATABASEA collection of schemas and objects
COLUMNA field in a table
ADDAdd a column or constraint (ALTER TABLE)
RENAMERename a table or column
IF EXISTSAvoid error if object is missing (DROP)
IF NOT EXISTSAvoid error if object already exists (CREATE)
TEMPORARYCreate a session-scoped table

Constraints

KeywordDescription
PRIMARY KEYUniquely identify each row
FOREIGN KEYReference a row in another table
REFERENCESSpecify the target of a foreign key
UNIQUEPrevent duplicate values in a column
NOT NULLDisallow NULL values
CHECKEnforce a boolean expression on column values
DEFAULTProvide a fallback value when none is given
CONSTRAINTName a table constraint explicitly
AUTO_INCREMENTAuto-generate sequential IDs (MySQL)
SERIALAuto-incrementing integer column (PostgreSQL)
AUTOINCREMENTStrict auto-increment (SQLite)
IDENTITYAuto-incrementing column (SQL Server, SQL standard)
CASCADEPropagate deletes/updates to child rows
RESTRICTPrevent delete/update if child rows exist

Operators & Predicates

KeywordDescription
ANDLogical AND
ORLogical OR
NOTLogical negation
INMatch any value in a list or subquery
BETWEENMatch a range (inclusive)
LIKEPattern match with % and _ wildcards
ILIKECase-insensitive LIKE (PostgreSQL)
IS NULLTest for NULL
IS NOT NULLTest for non-NULL
EXISTSTrue if subquery returns any row
ANYCompare to any value from a subquery
SOMESynonym for ANY
CASEConditional expression (CASE WHEN ... THEN ... ELSE ... END)
WHENBranch inside a CASE expression
THENResult for a CASE WHEN branch
ELSEDefault CASE result
ENDClose a CASE or BEGIN block
ASAlias a column or table
CASTConvert a value to a different type
COALESCEReturn first non-NULL argument
NULLIFReturn NULL if two values are equal

Aggregate Functions

KeywordDescription
COUNTNumber of rows
SUMTotal of numeric values
AVGAverage of numeric values
MINSmallest value
MAXLargest value
STRING_AGGConcatenate strings with delimiter (PostgreSQL, SQL Server)
GROUP_CONCATConcatenate strings (MySQL, SQLite)
ARRAY_AGGCollect values into an array (PostgreSQL)

Window Functions

KeywordDescription
OVERDefine a window for the function
PARTITION BYDivide rows into groups within a window
ROW_NUMBERSequential integer per partition
RANKRank with gaps on ties
DENSE_RANKRank without gaps on ties
NTILEDistribute rows into N buckets
LAGValue from a previous row
LEADValue from a following row
FIRST_VALUEFirst value in the window frame
LAST_VALUELast value in the window frame
ROWSPhysical row-based window frame
RANGELogical value-based window frame

Transaction Control

KeywordDescription
BEGINStart a transaction
COMMITSave all changes since BEGIN
ROLLBACKUndo all changes since BEGIN
SAVEPOINTCreate a named restore point
RELEASERemove a savepoint
LOCKAcquire a table or row lock

Access Control (DCL)

KeywordDescription
GRANTGive permissions to a user or role
REVOKERemove permissions from a user or role
ROLEA named set of permissions
USERA database account

Common Table Expressions & Subqueries

KeywordDescription
WITHDefine a Common Table Expression (CTE)
RECURSIVEAllow a CTE to reference itself
LATERALSubquery that references preceding FROM items (PostgreSQL)

Data Types (cross-database)

KeywordDescription
INTEGERWhole number (INT is a common alias)
BIGINT64-bit integer
SMALLINT16-bit integer
DECIMALExact fixed-point number (NUMERIC is equivalent)
FLOATApproximate floating-point number
DOUBLE PRECISION64-bit floating-point
BOOLEANTrue or false
VARCHARVariable-length string
CHARFixed-length string
TEXTUnlimited-length string
DATECalendar date (year, month, day)
TIMETime of day
TIMESTAMPDate and time
INTERVALTime span
BLOBBinary large object
JSONJSON data (MySQL, PostgreSQL)
JSONBBinary JSON with indexing (PostgreSQL)
UUIDUniversally unique identifier (PostgreSQL)
ARRAYArray of values (PostgreSQL)

Format your SQL

Paste raw SQL and get clean, consistently indented output with keyword highlighting.

Open SQL Formatter