On this page
CockroachDB supports the following SQL statements. Click a statement for more details.
Data Manipulation Statements
Statement | Usage |
---|---|
CREATE TABLE AS |
Create a new table in a database using the results from a SELECT statement. |
DELETE |
Delete specific rows from a table. |
EXPLAIN |
View debugging and analysis details for a SELECT , INSERT , UPDATE , or DELETE statement. |
INSERT |
Insert rows into a table. |
SELECT |
Select rows from a table. |
TRUNCATE |
Deletes all rows from specified tables. |
UPDATE |
Update rows in a table. |
UPSERT |
Insert rows that do not violate uniqueness constraints; update rows that do. |
Data Definition Statements
Statement | Usage |
---|---|
ADD COLUMN |
Add columns to a table. |
ADD CONSTRAINT |
Add a constraint to a column. |
ALTER COLUMN |
Change a column's Default constraint or drop the Not Null constraint. |
ALTER TABLE |
Apply a schema change to a table. |
ALTER VIEW |
Rename a view. |
CREATE DATABASE |
Create a new database. |
CREATE INDEX |
Create an index for a table. |
CREATE TABLE |
Create a new table in a database. |
CREATE TABLE AS |
Create a new table in a database using the results from a SELECT statement. |
CREATE VIEW |
Create a new view in a database. |
DROP COLUMN |
Remove columns from a table. |
DROP CONSTRAINT |
Remove constraints from a column. |
DROP DATABASE |
Remove a database and all its objects. |
DROP INDEX |
Remove an index for a table. |
DROP TABLE |
Remove a table. |
DROP VIEW |
Remove a view. |
RENAME COLUMN |
Rename a column in a table. |
RENAME DATABASE |
Rename a database. |
RENAME INDEX |
Rename an index for a table. |
RENAME TABLE |
Rename a table or move a table between databases. |
SHOW COLUMNS |
View details about columns in a table. |
SHOW CONSTRAINTS |
List constraints on a table. |
SHOW CREATE TABLE |
View the CREATE TABLE statement that would create a carbon copy of the specified table. |
SHOW CREATE VIEW |
View the CREATE VIEW statement that would create a carbon copy of the specified view. |
SHOW DATABASES |
List databases in the cluster. |
SHOW INDEX |
View index information for a table. |
SHOW TABLES |
List tables in a database. |
Transaction Management Statements
Statement | Usage |
---|---|
BEGIN |
Initiate a transaction. |
COMMIT |
Commit the current transaction. |
RELEASE SAVEPOINT |
When using the CockroachDB-provided function for client-side transaction retries, commit the transaction's changes once there are no retryable errors. |
ROLLBACK |
Discard all updates made by the current transaction or, when using the CockroachDB-provided function for client-side transaction retries, rollback to the cockroach_restart savepoint and retry the transaction. |
SAVEPOINT |
When using the CockroachDB-provided function for client-side transaction retries, start a retryable transaction. |
SET TRANSACTION |
Set the isolation level or priority for the session or for an individual transaction. |
SHOW |
View the current transaction settings. |
Privilege Management Statements
Statement | Usage |
---|---|
CREATE USER |
Creates a SQL user, which lets you control privileges on your databases and tables. |
GRANT |
Grant privileges to users. |
REVOKE |
Revoke privileges from users. |
SHOW GRANTS |
View privileges granted to users. |
SHOW USERS |
Lists the users for all databases. |
Session Management Statements
Statement | Usage |
---|---|
SET |
Set the current session parameters. |
SET TRANSACTION |
Set the isolation level or priority for an individual transaction. |
SHOW |
List the current session or transaction settings. |
Cluster Management Statements
Statement | Usage |
---|---|
SHOW ALL CLUSTER SETTINGS |
List the current cluster-wide settings. |
SET CLUSTER SETTING |
Set a cluster-wide setting. |
Backup & Restore Statements (Enterprise)
The following statements are available only to enterprise license users.
Statement | Usage |
---|---|
BACKUP |
Create disaster recovery backups of databases and tables. |
RESTORE |
Restore databases and tables using your backups. |