Using Worksheets for Queries / DML / DDL¶
The Worksheets page of the Classic Console provides a powerful and versatile interface for creating and submitting SQL queries, as well as performing most other DML and all DDL operations, and viewing the results as your statements complete.
This topic provides details about Classic Console. If you’re using Snowsight, see Managing and using worksheets in Snowsight.
Overview of Features¶
Add a worksheet.
Manage worksheets (search for, open or delete, rename).
Open a tutorial.
Load a script.
Change the current database, schema, or warehouse for the current worksheet without losing your work.
Resume/suspend or resize your current warehouse.
Load a script.
Enable/disable text highlighting.
Show/hide Run confirmation.
Delete the current worksheet.
Copy results to clipboard.
Hide or show columns.
Worksheets are designed to meet all your business and workflow needs, including:
Running ad hoc queries and performing other SQL operations.
Opening multiple, concurrent worksheets, each with its own separate session, allowing you to run queries in different worksheets with different contexts without any degradation in UI performance.
Saving a worksheet for later use.
Opening a worksheet from your library of saved worksheets.
Saved worksheets are not accessible outside of the Classic Console.
Saved worksheets cannot currently be shared with other users.
Loading SQL script files from your workstation or network into a worksheet. After you’ve loaded a script file, you can optionally edit and save it to your library of saved worksheets.
Logging out without losing your work. Snowflake retains the static contents of each worksheet, so you can log in again later and resume working where you left off. Snowflake displays the worksheets that were open when you logged out.
Note that resized/collapsed panes, width changes to the result/data preview columns, and even the cursor position in the SQL editor, are persisted:
When switching between open worksheets.
When closing and reopening the same worksheet.
Between user sessions.
Specifying a different role for each worksheet and switching roles without losing your work. You can execute specific statements in a worksheet, then switch roles before continuing your work in the same worksheet.
Your current interface role determines the default role for worksheets that you open, but the worksheets are not tied to the interface role. Each worksheet has its own role that can be set independently.
Logging into Snowflake in another browser or tab. Any worksheet changes you made in one Snowflake instance persist to the other instance after a minute or two. You can continue working in the other browser (or tab) without re-entering your work.
Refreshing your browser, if necessary. If you’re in the middle of running queries, they will resume running when the refresh is completed. Note that if you log out of Snowflake, any active queries stop running.
You can also perform other tasks on this page, including:
Resizing the current warehouse to dynamically increase or decrease the compute resources utilized for executing your queries and other DML statements.
Exporting the result for a selected query/statement (if the result is still available). For more information, see Exporting Query Results.
Saving and Managing Worksheets¶
Snowflake automatically saves worksheets as you type and persists the current state of a worksheet between user sessions. To organize your worksheets, double-click on the worksheet label in the tab
Worksheet 2) and type a new, more meaningful name for the worksheet (e.g.
To open a closed worksheet, click the down-arrow to the right of the open worksheet tabs, and click Open Worksheet. The Open Worksheet dialog opens.
Search for worksheets by label.
Delete selected worksheets.
Click on a row to select a single worksheet.
Click the CMD (Mac) or CTRL (Windows) key once and then click on multiple rows to select multiple worksheets.
Double-click a label to edit it.
Open selected worksheets.
The Open Worksheet dialog supports the following actions:
Search for individual worksheets by label.
Enter text in the Search field. The list of existing worksheets is filtered automatically.
Edit worksheet labels.
Double-click on a worksheet label, and edit the text. Worksheet labels are limited to 255 characters.
Open or delete one or more worksheets.
Using the Object Browser¶
Preview table data.
Double-click to insert name into SQL editor.
The object browser enables users to explore all databases, schemas, tables, and views accessible by the role selected for a worksheet.
The list of databases and other objects refreshes automatically when the worksheet context is changed. Users can also click the refresh button at the top of the object browser to view object changes immediately.
The object browser can be collapsed at any time to make more room for the SQL editor and results/history panes.
Exploring Database Objects¶
Click on a database or schema to explore the database objects contained within. You can then drill down to the table and view level.
Preview table/view data in the data preview pane
Set a database or schema in the object browser as the context for the worksheet
Insert the fully-qualified name of a database or object into the SQL editor at the cursor position
Searching for Database Objects¶
Search for databases, schemas, tables, and views using the Find database objects field. Note that searches are “starts with” searches, and are also case-insensitive unless the search string is enclosed in double quotes.
You can also search within a database or schema using the search icon that appears for the item when you hover over it in the object browser.
Click the context menu to select a different active warehouse for the worksheet. You can resume or suspend the selected warehouse, or resize the warehouse.
The query details and results displayed in the worksheet are only maintained for your current user session. If you log out of the web interface and log back in, the results from your previous session are no longer displayed in the worksheet; however, you can use the History page to see queries you executed in previous sessions.
Execute queries in the SQL editor using any one of the following options:
Execute single query
With your cursor anywhere in the query, type the following key combination:
Execute all queries
Execute single/multiple queries (with confirmation)
Execute all queries (with confirmation)
With no queries selected, type the following key combination:
Aborting Running Queries¶
While queries are running, the Run button changes to an Abort button. Click this button to abort the running queries.
Viewing Query Information and Details¶
When a query is executed, a status bar displays the current total query duration. Hover over the bar to see a breakdown of the duration.
Hover over to view query metrics.
Click the Query ID link to explore query details. A popover provides links to copy the query ID to your operating system’s temporary memory or to navigate to the query history.
Click to copy the query ID.
Click to navigate to the query history.
Formatting Queries Using Keyboard Shortcuts¶
The SQL editor in a worksheet supports the following keyboard keys and key combinations for formatting your queries and other SQL statements:
- Tab Stops:
To insert a tab stop in a line (in 4 character intervals), use the [TAB] key:
If the cursor is at the beginning of the line, 4 blank spaces are inserted.
If the cursor is in the line, enough blank spaces are added to reach the next tab stop.
To indent/outdent a line (or multiple lines) 2 blank spaces, place the cursor anywhere in the line (or highlight the desired lines), hold down the [CMD] (Mac) or [CTRL] (Windows) key and type one or more:
Right square brackets,
], to indent the line(s) the number of brackets typed.
Left square brackets,
[, to outdent the line(s) the number of brackets typed.
If a line is indented, all new lines after the indented line are automatically indented the same number of blank spaces.
To comment out a line (or multiple lines), place the cursor anywhere in the line (or highlight the desired lines), hold down the [CMD] (Mac) or [CTRL] (Windows) key and type a forward slash,
- Text Highlighting:
To enable or disable text highlighting in all open worksheets, place the cursor anywhere in a worksheet, hold down the [SHIFT]+[CMD] (Mac) or [SHIFT]+[CTRL] (Windows) keys and type the letter
- Add Multiple Cursors:
To add multiple cursors in the same worksheet, hold down the [CMD] (Mac) or [CTRL] (Windows) key and click in each new location using the mouse left button or the touchpad.
- Select Text Area:
To select a text area, hold down the [OPTION] (Mac) or [ALT] (Windows) key. The cursor turns into a crosshair. Cick and drag using the mouse left button or the touchpad.
- Find and Replace Text Strings:
To search for and replace a text string in a worksheet:
Hold down the [CMD]+[OPT]+[F] (Mac) or [SHIFT]+[CTRL]+[F] (Windows) keys. A Replace field displays.
To replace all instances of a text string, hold down the [CMD]+[OPT]+[SHIFT]+[F] (Mac) or [ALT]+[CTRL]+[SHIFT]+[F] (Windows) keys. A Replace All field displays.
Type the string to replace, and press the Enter key. A With field displays.
Type the replacement string, and press the Enter key. A set of options displays.
Click the desired option:
Replace the current instance of the string with the specified replacement and advance to the next instance.
Retain the current instance of the string and advance to the next instance.
Replace all instances of the string with the specified replacement.
Stop searching for instances of the string.
These keyboard shortcuts are specific to the Classic Console. For shortcuts in Snowsight, see Update worksheets with keyboard shortcuts.
Backing Up Your Own Worksheets¶
We recommend that users back up complex or crucial worksheets that would be difficult to recreate. Copy and paste the contents of individual worksheets into files that you can safeguard. Backing up your worksheets prevents them from accidental deletion.
Worksheet metadata is stored in the Snowflake user stage, in the
worksheet_data directory. Executing the REMOVE command and removing the
worksheet_data directory deletes your own worksheets, which cannot be restored.
This precaution applies to worksheets in the Worksheets tab in the Classic Console only. Worksheets in Snowsight are stored elsewhere and are not prone to accidental deletion.