Skip to main content
CockroachDB supports the following SQL statements. In the , use \h [statement] to get inline help about a statement.

Data definition statements

StatementUsage
Apply a schema change to a database.
Change the default for objects created by specific roles/users in the current database.
Modify a .
Apply a schema change to an index.
Configure the replication zone for a partition.
Modify a .
Configure the replication zone for a system range.
Alter a user-defined schema.
Apply a schema change to a sequence.
Apply a schema change to a table.
Modify a user-defined, .
Add, change, or remove a user’s password and to change the login privileges for a role.
Add, change, or remove a password and to change the login privileges for a role.
Apply a schema change to a view.
Associate a comment to a database, table, or column.
Create a new database.
Create a .
Create an index for a table.
Create a .
Create a user-defined schema.
Create a new sequence.
Create a new table in a database.
Create a new table in a database using the results from a .
Create a new on a specified table.
Create a user-defined, .
Create a new in a database.
Remove a database and all its objects.
Remove a from a database.
Remove an index for a table.
Drop all objects owned by and any on objects not owned by a .
Remove a .
Drop a user-defined schema.
Remove a sequence.
Remove a table.
Remove a .
Remove a user-defined, .
Remove a view.
Refresh the stored query results of a .
View details about columns in a table.
List constraints on a table.
View the CREATE statement for a database, function, sequence, table, or view.
List databases in the cluster.
List the values for updated that are applied to a given .
List user-defined, in a database.
List recent queries that used a full table scan.
View index information for a table or database.
View the locality of the current node.
List partitions in a database.
List the or in a .
List the associated with a database in a .
List the schemas in a database.
List the sequences in a database.
List tables or views in a database or virtual schema.
List user-defined in a database.
Show range information for all data in a table or index.
Show range information for a single row in a table or index.
List details about existing .

Data manipulation statements

StatementUsage
Create a new table in a database using the results from a .
Copy data from a third-party client to a CockroachDB cluster.
For compatibility with PostgreSQL drivers and ORMs, CockroachDB supports COPY FROM statements issued from third-party clients. To import data from files, use an statement instead.
Delete specific rows from a table.
Execute a code block.
Export an entire table’s data, or the results of a SELECT statement, to CSV files.
Bulk-insert CSV data into an existing table.
Insert rows into a table.
Select specific rows and columns from a table and optionally compute derived values.
Order transactions by controlling concurrent access to one or more rows of a table.
Select all rows and columns from a table.
Delete all rows from specified tables.
Update rows in a table.
Insert rows that do not violate uniqueness constraints; update rows that do.
Return rows containing specific values.

Data control statements

StatementUsage
Create SQL , which are groups containing any number of roles and users as members.
Create SQL users, which lets you control on your databases and tables.
Remove one or more SQL .
Remove one or more SQL users.
Grant privileges to , or add a or as a member to a role.
Change the of all database objects in the current database that are currently owned by a specific or .
Revoke privileges from or , or revoke a or membership to a role.
View privileges granted to users.
Lists the roles for all databases.
Lists the users for all databases.
Show the default privileges for objects created by specific roles/users in the current database.

Transaction control statements

StatementUsage
Initiate a .
Call a .
Commit the current .
Start a .
Commit a .
Roll back and restart the started at the corresponding SAVEPOINT statement.
Roll back the current and all of its , discarding all transactional updates made by statements inside the transaction.
Set the priority for the session or for an individual .
View the current .
View all currently active transactions across the cluster or on the local node.

Session management statements

StatementUsage
Reset a session variable to its default value.
Set a current session variable.
Set the priority for an individual .
Return details about how CockroachDB executed a statement or series of statements recorded during a session.
List the current session or transaction settings.

Cluster management statements

StatementUsage
Reset a cluster setting to its default value.
Set a cluster-wide setting.
List the current cluster-wide settings.
List details about currently active sessions.
Cancel a long-running session.

Query management statements

StatementUsage
Cancel a running SQL query.
List details about current active SQL queries.

Query planning statements

StatementUsage
Create table statistics for the to use.
View debugging and analysis details for a statement that operates over tabular data.
Execute the query and generate a physical query plan with execution statistics.
List table statistics used by the .

Job management statements

Jobs in CockroachDB represent tasks that might not complete immediately, such as schema changes or backups or restores.
StatementUsage
Cancel a BACKUP, RESTORE, IMPORT, or CHANGEFEED job.
Pause a BACKUP, RESTORE, IMPORT, or CHANGEFEED job.
Resume a paused BACKUP, RESTORE, IMPORT, or CHANGEFEED job.
View information on jobs.

Backup and restore statements

StatementUsage
Create disaster recovery backups of clusters, databases, and tables.
Restore clusters, databases, and tables using your backups.
List the contents of a backup.
Create a schedule for periodic backups.
Modify an existing backup schedule.
View information on backup schedules.
Pause backup schedules.
Resume paused backup schedules.
Drop backup schedules.
Add a new to an encrypted backup.

Changefeed statements

(CDC) provides an and core version of row-level change subscriptions for downstream processing.
StatementUsage
Create a new changefeed to stream row-level changes in a configurable format to a configurable sink (e.g, , ).
Create a scheduled changefeed to export data out of CockroachDB using an initial scan. to a configurable sink (e.g, , ).
(Core) Create a new changefeed to stream row-level changes to the client indefinitely until the underlying connection is closed or the changefeed is canceled.
Modify an existing changefeed.

External resource statements

StatementUsage
Create an external connection, which represents a provider-specific URI, to interact with resources that are external from CockroachDB.
Display the connection name and the creation statements for active external connections.
Drop an external connection.