SQL DDL and DML
Create and change schema objects, then insert, update, delete, merge, and manage transactional data changes.
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## CREATE, ALTER, and DROP
## Constraints and Indexes
## INSERT, UPDATE, and DELETE
MERGE INTO inventory AS target USING incoming_inventory AS src ON target.sku = src.sku WHEN MATCHED THEN UPDATE SET quantity = src.quantity WHEN NOT MATCHED THEN INSERT (sku, quantity) VALUES (src.sku, src.quantity);
# Insert new rows and update existing ones in one logical operation.
## Transactions
More in SQL
SQL Indexing and Performance
Query tuning patterns with EXPLAIN, indexing, keyset pagination, deduplication, and optimization-oriented SQL recipes.
SQL Window Functions and CTEs
Use CTEs, recursive queries, ranking, running totals, partitions, and lag/lead patterns for analytical SQL.
SQL Functions and Aggregation
Reference for string, date, numeric, conditional, null-handling, and aggregate SQL functions.
SQL Joins and Subqueries
Advanced relational query patterns for joins, subqueries, EXISTS, IN, set operations, and correlated queries.
SQL Cheat Sheet
Core SQL syntax and patterns for querying, filtering, sorting, joining, grouping, and modifying data.