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

# SQL Shell

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

export const version = "stable";

<Note>
  **This feature is in <InternalLink path="cockroachdb-feature-availability">preview</InternalLink>** and subject to change. To share feedback and/or issues, contact [Support](https://support.cockroachlabs.com).
</Note>

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 <InternalLink version="cockroachcloud" path="cluster-management#view-clusters-page">**Clusters** page</InternalLink>, 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 <InternalLink version="stable" path="set-cluster-setting">SET CLUSTER SETTING</InternalLink> statement to configure cluster settings.
* The SQL Shell does not yet support sessions.
* The SQL Shell is not available for CockroachDB Advanced clusters with <InternalLink path="managing-access">additional security add-ons configured</InternalLink>.
* The SQL Shell is available to CockroachDB Cloud users with the <InternalLink path="create-an-advanced-cluster#step-6-configure-advanced-security-features">Cluster Admin role</InternalLink>.
* The SQL Shell does not support <InternalLink version="stable" path="sql-statements#transaction-control-statements">transaction control statements</InternalLink>.
* The SQL Shell does not support the <InternalLink version="stable" path="call">`CALL` statement</InternalLink> 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 <InternalLink path="managing-access">Cluster Admin role</InternalLink> needed to access the Cloud Console SQL Shell can still access CockroachDB's <InternalLink version="stable" path="cockroach-sql">command line SQL shell</InternalLink>.

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 <InternalLink path="create-a-basic-cluster">created a CockroachDB Cloud cluster</InternalLink> and have [access](#limitations) to the SQL Shell.

1. In the SQL Shell, run <InternalLink version="stable" path="create-table">`CREATE TABLE`</InternalLink> followed by a table name, the column names, and the <InternalLink version="stable" path="data-types">data type</InternalLink> and <InternalLink version="stable" path="constraints">constraint</InternalLink>, 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 <InternalLink version="stable" path="insert">`INSERT INTO`</InternalLink> 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 <InternalLink version="stable" path="select-clause">`SELECT`</InternalLink> 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

* <InternalLink version="stable" path="cockroach-sql">`cockroach sql`</InternalLink>
* <InternalLink version="stable" path="learn-cockroachdb-sql">Learn CockroachDB SQL</InternalLink>
