Using worksheets for queries / DML / DDL¶
Use the Worksheets page of the Classic Console to create and submit SQL queries, perform DML and all DDL operations, and view statement results.
Note
This topic provides details about Classic Console. If you’re using Snowsight, see Work with worksheets in Snowsight.
Features overview¶
Object browser.
Add a worksheet.
Drop-down menu:
Manage worksheets (search, open or delete, rename).
Open a tutorial.
Load a script.
Drop-down menu:
Change the current database, schema, or warehouse for the current worksheet without losing your work.
Resume/suspend or resize your current warehouse.
Drop-down menu:
Load a script.
Enable or disable text highlighting.
Show/hide Run confirmation.
Delete the current worksheet.
SQL editor.
Download results.
Copy results to clipboard.
Maximize or restore results.
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 performance.
Saving a worksheet for later use.
Opening a worksheet from your library of saved worksheets.
Note
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 saved worksheet library.
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.
Resized or collapsed panes, width changes to the result and data preview columns, and the cursor position in the SQL editor, persist:
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.
Note
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 few minutes. 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 resume running when the refresh is completed. 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.
Save and manage 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 the worksheet label in the tab (for example, Worksheet 2
) and type a new, more meaningful name for the worksheet
(for example, Sales Analysis
).
To open a closed worksheet, click the down-arrow to the right of the open worksheet tabs, and click Open Worksheet.
Search for worksheets by label.
Delete selected worksheets.
Click on a row to select a single worksheet.
Press 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:
Action |
Steps |
---|---|
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 a worksheet label, and edit the text. Worksheet labels are limited to 255 characters. |
Open or delete one or more worksheets. |
|
Use 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. You can also select Refresh 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.
Explore database objects¶
Select a database or schema to explore the database objects it contains. You can then drill down to the table and view level.
Action |
Options |
Notes |
---|---|---|
Preview table/view data in the data preview pane |
|
|
Set a database or schema in the object browser as the context for the worksheet |
|
This is a shortcut to selecting the Context bar in the upper right and selecting the database/schema from the drop-down menus. |
Insert the fully-qualified name of a database or object into the SQL editor at the cursor position |
|
Search for database objects¶
Search for databases, schemas, tables, and views using the Find database objects field. 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.
Manage warehouses¶
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.
Manage queries¶
Important
The query details and results displayed in the worksheet are only maintained for your current user session. If you sign 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¶
Execute queries in the SQL editor using any one of the following options:
Action |
Steps |
Keyboard Shortcuts |
---|---|---|
Execute single query |
|
With your cursor anywhere in the query, type the following key combination:
|
Execute all queries |
|
N/A (None) |
Execute single/multiple queries (with confirmation) |
|
N/A (None) |
Execute all queries (with confirmation) |
|
With no queries selected, type the following key combination:
|
While queries are running, the Run button text changes to Abort. Select Abort to abort the running queries.
View query 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 popup 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.
Use keyboard shortcuts to format queries¶
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.
- Indents/Outdents:
To indent/outdent a line (or multiple lines) two 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.
- Comments:
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
K
.- 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 with the left mouse 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. Click and drag using the left mouse button or the touchpad.
- Find and Replace Text Strings:
To search for and replace a text string in a worksheet:
Hold down the CMD + option + F (Mac) or SHIFT + CTRL + F (Windows) keys. A Replace field displays.
To replace all instances of a text string, hold down the CMD + option + 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:
- Yes:
Replace the current instance of the string with the specified replacement and advance to the next instance.
- No:
Retain the current instance of the string and advance to the next instance.
- All:
Replace all instances of the string with the specified replacement.
- Stop:
Stop searching for instances of the string.
Note
These keyboard shortcuts are specific to the Classic Console. For shortcuts in Snowsight, see Perform tasks with keyboard shortcuts.
Back up your worksheets¶
Snowflake recommends that you 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. Deleted worksheets
cannot be restored.
Note
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.