Using Worksheets for Queries / DML / DDL¶
The Worksheets page 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.
In this Topic:
Overview of Features¶
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 Snowflake web interface.
- 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.
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¶
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.
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.
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:
To insert a tab stop in a line (in 4 character intervals), use the [TAB] key:
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:
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
|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.|