> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL Shell

> [!NOTE]
>
> **This feature is in [preview](https://docs.cockroachlabs.com/docs/releases/cockroachdb-feature-availability.md)** and subject to change. To share feedback and/or issues, contact [Support](https://support.cockroachlabs.com).

The **SQL Shell** page on the Console enables you to run queries on your cluster directly from your browser.

To use this feature, select a cluster from the [**Clusters** page](https://docs.cockroachlabs.com/docs/cockroachcloud/cluster-management.md#view-clusters-page), and navigate to the cluster's **SQL Shell** page.

## Limitations

* All statements in the SQL Shell are executed within a transaction, so you cannot use the [SET CLUSTER SETTING](https://docs.cockroachlabs.com/docs/stable/set-cluster-setting.md) statement to configure cluster settings.
* The SQL Shell does not yet support sessions.
* The SQL Shell is not available for CockroachDB Advanced clusters with [additional security add-ons configured](https://docs.cockroachlabs.com/docs/cockroachcloud/managing-access.md).
* The SQL Shell is available to CockroachDB Cloud users with the [Cluster Admin role](https://docs.cockroachlabs.com/docs/cockroachcloud/create-an-advanced-cluster.md#step-6-configure-advanced-security-features) or the [Cluster Data Accessor role](https://docs.cockroachlabs.com/docs/cockroachcloud/authorization.md#cluster-data-accessor).
* The SQL Shell does not support [transaction control statements](https://docs.cockroachlabs.com/docs/stable/sql-statements.md#transaction-control-statements).
* The SQL Shell does not support the [`CALL` statement](https://docs.cockroachlabs.com/docs/stable/call) used to invoke a stored procedure.

## Overview

Above the SQL Shell input field, you will see the active user and cluster details in the format `{user name} @ {cluster-name}:{active-database}`. Note that the user displayed is the **Team member** currently logged into the Cloud Console, not the active SQL user, which is `root`. Team members without the [Cluster Admin or Cluster Data Accessor role](https://docs.cockroachlabs.com/docs/cockroachcloud/managing-access.md) needed to access the Cloud Console SQL Shell can still access CockroachDB's [command line SQL shell](https://docs.cockroachlabs.com/docs/stable/cockroach-sql.md).

You can change the active database in the dropdown menu above the input field. If you create a new database in the SQL Shell, you will have to reload the page to refresh the database dropdown menu. Reloading the page will also clear your activity.

To execute a SQL statement, enter it in the input field and either click **Run** or use the **Enter** key. The statement status will be **Loading** until it either **Succeeds** or returns an **Error**. Any results returned can be exported by clicking the **Export results** button below the executed statement.

You can select any statement that you've previously run and copy it, edit it, or re-run it.

## Example workflow

The following examples assume you have already [created a CockroachDB Cloud cluster](https://docs.cockroachlabs.com/docs/cockroachcloud/create-a-basic-cluster.md) and have [access](#limitations) to the SQL Shell.

1. In the SQL Shell, run [`CREATE TABLE`](https://docs.cockroachlabs.com/docs/stable/create-table) followed by a table name, the column names, and the [data type](https://docs.cockroachlabs.com/docs/stable/data-types.md) and [constraint](https://docs.cockroachlabs.com/docs/stable/constraints.md), if any, for each column:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > CREATE TABLE dogs (
       id INT PRIMARY KEY,
       name STRING
   );
   ```
2. Insert rows into the table using [`INSERT INTO`](https://docs.cockroachlabs.com/docs/stable/insert) followed by the table name and then the column values listed in the order in which the columns appear in the table:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > INSERT INTO dogs VALUES (1, 'Petee'), (2, 'Carl');
   ```
3. Click the copy icon next to the successful `INSERT INTO` statement, paste it into the input field, edit the values, and run it again:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > INSERT INTO dogs VALUES (3, 'Blue'), (4, 'Clifford');
   ```
4. Query the table with [`SELECT`](https://docs.cockroachlabs.com/docs/stable/select-clause) followed by a comma-separated list of the columns to be returned and the table from which to retrieve the data:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > SELECT name FROM dogs;
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
        | name
   +----+----------+
      1 | Petee
      2 | Carl
      3 | Blue
      4 | Clifford
   ```
5. Edit the executed `SELECT` statement to replace `name` with the `*` wildcard symbol and click **Run**:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > SELECT * FROM dogs;
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
        | id | name
   +----+----------+
     1  | 1 | Petee
     2  | 2 | Carl
     3  | 3 | Blue
     4  | 4 | Clifford
   ```

   Note that each line of a query's results will be numbered independently of the output. This is for readability and will not be shown in any exported data.
6. Click **Export results** to download a CSV file of the output.

## See also

* [`cockroach sql`](https://docs.cockroachlabs.com/docs/stable/cockroach-sql)
* [Learn CockroachDB SQL](https://docs.cockroachlabs.com/docs/stable/learn-cockroachdb-sql)
