CROSS-PLATFORM COMMAND ATLAS

SQL reference

Common SQL statements and patterns, with notes for six database dialects.

56 entriesSyntax and availability can vary by version, edition, installed modules and configuration. Follow the linked upstream documentation.
/
56 entries
Query

SQL SELECT

Query rows from one or more tables.

SELECT [DISTINCT] column_list FROM table_name [WHERE condition] [GROUP BY columns] [HAVING condition] [ORDER BY columns] [LIMIT count];Open guide
Data changes

SQL INSERT

Add rows to a table.

INSERT INTO table_name (column_a, column_b) VALUES (value_a, value_b);Open guide
Data changes

SQL UPDATE

Change values in existing rows.

UPDATE table_name SET column = value [, column = value] WHERE condition;Open guide
Data changes

SQL MERGE / UPSERT

Insert or update rows according to a match condition; syntax differs by database.

MERGE INTO target USING source ON match_condition WHEN MATCHED THEN UPDATE SET ... WHEN NOT MATCHED THEN INSERT ...;Open guide
Schema

SQL ALTER TABLE

Change a table definition; supported operations vary by dialect.

ALTER TABLE table_name ADD COLUMN column_name data_type;Open guide
Schema

SQL CREATE INDEX

Create an index to support selected query patterns.

CREATE [UNIQUE] INDEX index_name ON table_name (column_list);Open guide
Query

SQL JOIN

Combine rows from related tables using a join condition.

SELECT columns FROM left_table [INNER|LEFT|RIGHT|FULL] JOIN right_table ON condition;Open guide
Query

SQL WITH (CTE)

Define a common table expression for a single statement.

WITH cte_name AS (SELECT ...) SELECT ... FROM cte_name;Open guide
Query

SQL CASE

Return a value based on conditional branches.

CASE WHEN condition THEN value [ELSE value] ENDOpen guide
Access control

SQL GRANT

Grant privileges to a database principal; privilege names and scope vary by engine.

GRANT privilege ON object TO principal;Open guide
Access control

SQL REVOKE

Remove previously granted privileges where supported.

REVOKE privilege ON object FROM principal;Open guide
Transactions

SQL ROLLBACK

Undo uncommitted changes in the current transaction where supported.

ROLLBACK [TRANSACTION];Open guide
Administration

SQL EXPLAIN

Show a query execution plan; output and options differ by engine.

EXPLAIN [options] query;Open guide
Administration

SQL Inspect tables and schemas

Inspect schema metadata; these commands are client-specific rather than portable SQL.

Use the database client's schema inspection command or query its information schema/catalog.Open guide
Query

SQL GROUP BY

Group rows for aggregate calculations.

SELECT expression, aggregate(...) FROM table GROUP BY expression;Open guide
Query

SQL Subqueries

Use a query as an expression, source or predicate inside another statement.

SELECT ... WHERE value IN (SELECT ...);Open guide
Schema

SQL Constraints

Enforce data rules using NOT NULL, UNIQUE, CHECK, PRIMARY KEY and FOREIGN KEY constraints.

CREATE TABLE ... (column type NOT NULL, UNIQUE (...), CHECK (...), FOREIGN KEY (...) REFERENCES ...);Open guide
Schema

SQL FOREIGN KEY

Enforce references between related tables when enabled and supported.

FOREIGN KEY (column) REFERENCES parent_table (column)Open guide
Access control

SQL GRANT / REVOKE

Manage database privileges; object scope, roles and syntax differ across engines.

GRANT privilege ON object TO principal; REVOKE privilege ON object FROM principal;Open guide
Administration

SQL CREATE TRIGGER

Run database logic in response to table events; trigger syntax varies substantially.

CREATE TRIGGER trigger_name ... ON table_name ...Open guide
Transactions

SQL SET TRANSACTION

Configure isolation or read/write behaviour within supported transaction contexts.

SET TRANSACTION ISOLATION LEVEL ...;Open guide