Snowflake - Context
Guidance Questions
-
What are the two ways you can set context parameters from within the Worksheets area of the webUI?
- Using the context bar and selecting from the dropdown.
- Hovering over the desired database/schema, left click and select
SET AS CONTEXT
. - Source
Notes:
- To use the worksheet you need to select a role first.
- The role determines which databases/schemas roles the worksheet has access to.
- The active role in Snowsight is the default used when creating a worksheet. Changing the active roles does not change the worksheet role.
- The UI does not allow multiple roles. The worksheet has an option to enable multiple roles with the
USE SECONDARY ROLES
command. - Each worksheet exists in it's own unique session tied to the browser tab, it can hold roles independently of the active role.
- Source
-
What is the command keyword used to set context parameters via the SQL Pane (as opposed to the drop menu)?
- Using the commands:
USE WAREHOUSE
USE DATABASE
USE SCHEMA
USE ROLE
USE SECONDARY ROLES
- The objects (db, schema, etc) that can be accessed depends on the active roles selected in the worksheet.
- A warehouse is required to load any data in the session or run any DML statements.
- If a DB or Scheme are not specified in the session, any references to those objects must be fully qualifies with the name of the database and schema, AKA they need to come with a namespace.
- Fully Qualified name:
USE dbNAME.schemaNAME;
- Not fully qualified name:
USE DATABASE dbNAME; USE schemaName;
- Fully Qualified name:
- Source
- Using the commands:
-
What command is used with a context function like CURRENT_DATABASE() in order to return the current database name into the results pane?
- The database name consists of the warehouse, database and schema so the fully qualifies database name would need to return all of those values.
- The Query would look like this:
SELECT CURRENT_WAREHOUSE(), CURRENT_DATABASE(), CURRENT SCHEMA()
.
- Source
-
What context function will tell you the cloud infrastructure provider and the geographic region of your Snowflake account?
SELECT CURRENT_REGION()
- Source
-
Which context function can give you a unique id that refers to your current browser tab?
SELECT CURRENT_CLIENT()
- The result will be unique to each session AKA every separate browser tab.
- The result contains the current date + 4 random digits.
- Source
-
Which context function gives you a unique id that is roughly equivalent to your current worksheet?
SELECT CURRENT_SESSION()
- The result will be unique to each worksheet, while the
CURRENT_CLIENT()
will be the same for each worksheet in the same tab. - Source
Quiz
- You create a new worksheet in the WebUI. You want to set the user role, warehouse, database and schema context that will be used when running the SQL code.
- Run four
USE
commands, setting each context with a separate statement. - Use the Context drop menu in the upper right corner of the worksheet.
- Run four
- Which of these statements is a valid script-based way to set context in a Worksheet?
USE database MY_DATABASE;
USE schema MY_SCHEMA;
- Which of the following are valid context functions?
CURRENT_REGION()
CURRENT_SESSION()
CURRENT_CLIENT()
- Which context function returns information on the cloud infrastructure provider you chose when you first set up the Snowflake account?
CURRENT_REGION()
- Which command will return information about the current database?
SELECT CURRENT_DATABASE()
- If you click on the "History" in the ribbon, how far back in time are you able to view history?
- 14 days.
- if you want to view query history older than 14days, where can you go to view it? Chose one path and one "term" commonly used.
- The Account Usage Share.
- SNOWFLAKE(Database) -> ACCOUNT_USAGE(Schema) -> QUERY_HISTORY(Secure View)
- Which method for viewing query history provides more parameters/fields/attributes?
- The QUERY_HISTORY secure view available from the Account Usage Share.