SQL language reference
This is a SQL command reference for Databricks SQL and Databricks Runtime.
For information about how to understand and use the syntax notation and symbols in this reference, see How to use the SQL reference.
For information about using SQL with Lakeflow Spark Declarative Pipelines, see Pipeline SQL language reference.
General reference
This general reference describes data types, functions, identifiers, literals, and semantics.
Language fundamentals
Reference | Description |
|---|---|
Adding comments to your SQL code | |
Keywords reserved by the SQL parser | |
Rules for naming database objects | |
Object naming conventions | |
Dynamic identifier resolution | |
SQL expression syntax and evaluation | |
How NULL values are handled | |
Parameterized query placeholders | |
Session and temporary variables | |
How object names are resolved | |
Navigating JSON data structures | |
String comparison and sorting rules | |
Table partitioning concepts |
Data types
Reference | Description |
|---|---|
Overview of all supported data types | |
Type coercion and conversion rules | |
Format patterns for dates and times |
Configuration parameters
Reference | Description |
|---|---|
Overview of SQL configuration | |
ANSI SQL compliance mode | |
Time parsing behavior | |
File partition size limit | |
External metastore access mode | |
Query timeout setting | |
Session timezone | |
Query result caching |
Functions
Reference | Description |
|---|---|
Overview of SQL functions | |
All built-in functions | |
Complete A-Z function reference | |
Analytic and ranking functions | |
Anonymous function expressions | |
Hexagonal hierarchical spatial index | |
Standard geospatial functions | |
Custom aggregation functions | |
Custom scalar functions | |
Hive function compatibility | |
How to call functions |
Unity Catalog concepts
Reference | Description |
|---|---|
Users, groups, and service principals | |
Access control in Unity Catalog | |
Legacy metastore access control | |
Cloud storage locations | |
Tables backed by external data | |
Storage access credentials | |
Managed and external file storage |
Special topics
Reference | Description |
|---|---|
ANSI SQL standard compatibility | |
Hive SQL compatibility | |
Procedural SQL logic | |
Cross-organization data sharing | |
Querying external databases | |
Metadata system tables |
DDL statements
Data definition statements create or modify the structure of database objects.
ALTER statements
Statement | Description |
|---|---|
Modify catalog properties | |
Modify connection settings | |
Modify credential properties | |
Modify database properties | |
Modify external location | |
Modify materialized view | |
Modify data provider | |
Modify share recipient | |
Modify schema properties | |
Modify share configuration | |
Modify streaming table | |
Modify table structure | |
Modify view definition | |
Modify volume properties |
CREATE statements
Statement | Description |
|---|---|
Create bloom filter index | |
Create a new catalog | |
Create external connection | |
Create a new database | |
Create SQL function | |
Create external function | |
Create external location | |
Create materialized view | |
Create stored procedure | |
Create share recipient | |
Create a new schema | |
Create foreign server | |
Create data share | |
Create streaming table | |
Create a new table | |
Create a view | |
Create a volume |
DROP statements
Analyze statements
Other DDL statements
Statement | Description |
|---|---|
Add comments to objects | |
Declare session variable | |
Recover table partitions | |
Refresh foreign metadata | |
Refresh materialized data | |
Add tags to objects | |
Synchronize metadata | |
Remove all table data | |
Restore dropped table | |
Remove tags from objects |
DML statements
Data manipulation statements add, change, or delete data in Delta Lake tables.
Statement | Description |
|---|---|
Load data from files into a table | |
Delete rows from a table | |
Insert rows into a table | |
Write query results to directory | |
Write results in Hive format | |
Load data from files | |
Upsert data into a table | |
Update rows in a table |
Data retrieval statements
Retrieve rows from tables according to specified clauses. Databricks supports both standard SELECT syntax and SQL Pipeline Syntax.
Query statements
Statement | Description |
|---|---|
Full query syntax reference | |
Select data from tables | |
Construct inline table | |
Pipe-based query composition | |
Show query execution plan |
Query clauses
Clause | Description |
|---|---|
Column selection | |
Select all columns | |
Table and subquery sources | |
Combine rows from tables | |
Filter rows | |
Group rows for aggregation | |
Filter grouped rows | |
Filter window function results | |
Sort result rows | |
Sort within partitions | |
Distribute and sort data | |
Distribute data across partitions | |
Limit result rows | |
Skip result rows | |
Rotate rows to columns | |
Rotate columns to rows | |
Apply table-generating function | |
Sample table rows | |
Functions returning tables | |
Named subqueries | |
UNION, INTERSECT, EXCEPT | |
Named window definitions | |
Query optimizer hints |
Delta Lake statements
Manage tables stored in Delta Lake format. For details, see What is Delta Lake in Databricks?.
Statement | Description |
|---|---|
Cache query results | |
Convert Parquet to Delta | |
Show table history | |
Repair table metadata | |
Generate table manifest | |
Compact table files | |
Reorganize table data | |
Restore table to previous version | |
Remove old table files |
SQL scripting statements
Execute procedural logic in SQL. See SQL scripting for an overview.
Statement | Description |
|---|---|
Group statements into a block | |
Conditional branching | |
Loop over a range or cursor | |
Retrieve execution information | |
Conditional execution | |
Continue to next loop iteration | |
Exit a loop or block | |
Unconditional loop | |
Loop until condition is true | |
Re-raise an exception | |
Raise an exception | |
Loop while condition is true |
Auxiliary statements
Collect statistics, manage caching, explore metadata, set configurations, and manage resources.
ANALYZE statements
Statement | Description |
|---|---|
Compute table column statistics | |
Compute table storage metrics |
Cache statements
Applies to: Databricks Runtime
Statement | Description |
|---|---|
Cache table in memory | |
Remove all cached data | |
Refresh cached data | |
Refresh function metadata | |
Refresh table metadata | |
Remove table from cache |
DESCRIBE statements
Statement | Description |
|---|---|
Show catalog details | |
Show connection details | |
Show credential details | |
Show database details | |
Show function details | |
Show location details | |
Show procedure details | |
Show provider details | |
Show query output schema | |
Show recipient details | |
Show schema details | |
Show share details | |
Show table details | |
Show volume details |
SHOW statements
Statement | Description |
|---|---|
List files in a path | |
Show all objects in share | |
List catalogs | |
List table columns | |
List connections | |
Show table DDL | |
List credentials | |
List databases | |
List functions | |
List groups | |
List external locations | |
List table partitions | |
List procedures | |
List providers | |
List recipients | |
List schemas | |
List shares | |
List shares from provider | |
Show table information | |
List tables | |
List dropped tables | |
Show table properties | |
List users | |
List views | |
List volumes |
Configuration and variable management
Statement | Description |
|---|---|
Call a stored procedure | |
Execute dynamic SQL | |
Reset configuration to default | |
Set configuration parameter | |
Set share recipient context | |
Set session timezone | |
Set variable value | |
Set current catalog | |
Set current database | |
Set current schema |
Resource management
Applies to: Databricks Runtime
Statement | Description |
|---|---|
Add archive to session | |
Add file to session | |
Add JAR to session | |
List session archives | |
List session files | |
List session JARs |
Applies to: Databricks SQL Connector
Statement | Description |
|---|---|
Download file from volume | |
Upload file to volume | |
Delete file from volume |
Security statements
Manage access to data. For details, see Hive metastore privileges and securable objects (legacy).
Statement | Description |
|---|---|
Modify group membership | |
Create a new group | |
Deny privileges | |
Delete a group | |
Grant privileges | |
Grant share access | |
Repair privilege metadata | |
Revoke privileges | |
Revoke share access | |
Show granted privileges | |
Show share privileges | |
Show recipient privileges |