CertSafari
    Snowflake SnowPro Core Certification (COF-C03)· Lessons

    Domain 1 · Lesson 3/19

    Snowflake session context, SQL variables and parameter precedence

    Differentiate Snowflake object hierarchy and types

    10 min read
    5.17% of exam
    6 sources
    Published 20 Oct 2026
    Docs as of 18 Oct 2026

    What you will be able to do

    • Set and read a session's role, warehouse, database and schema with USE commands and context functions
    • Define, use and drop SQL variables, and predict when they disappear
    • Classify a parameter as account, session or object, and list the levels where each can be set
    • Work out which value of a parameter applies, and confirm where it came from with SHOW PARAMETERS

    1.Session context: role, warehouse, database and schema

    A session is one connection's working state, and four settings define its context: the current role, warehouse, database and schema. Each has its own USE command. USE ROLE sets the primary role, USE WAREHOUSE sets the compute that runs your queries, and USE DATABASE and USE SCHEMA set the namespace. The schema you choose has to be in the session's current database.

    The namespace context is why SELECT * FROM orders works without a database or schema prefix. Snowflake takes the database and schema from the session. If the session has no current database and schema, every object name must be fully qualified, and an unqualified name fails. A script that works in a worksheet can fail the same way when a scheduled job runs it in a fresh session with no context.

    To check the context from SQL, use context functions instead of querying views. CURRENT_USER() and CURRENT_WAREHOUSE() return the session's values directly. CURRENT_ORGANIZATION_NAME does the same one level higher in the hierarchy.

    Checkpoint 1 of 5· Check yourself

    A script runs SELECT * FROM orders without problems in a worksheet where a database and schema are set. A scheduled job then runs the same script in a fresh session, and no USE DATABASE or USE SCHEMA has been run in that session. What happens?

    Sources12

    2.SQL variables last only as long as the session

    A SQL variable is a named value you define in a session with SET. You can also pass one in the connection string, which helps with tools where the connection string is the only thing you can customise. The variable's data type comes from the value you assign, and a query that returns a single result can be assigned too. To refer to a variable, prefix its name with $ so Snowflake can tell it apart from column names and bind values.

    Setting two variables in one statement and using them as literalssql
    SET (min, max)=(40, 70);
    
    SELECT $min;
    
    SELECT AVG(salary) FROM emp WHERE age BETWEEN $min AND $max;

    A variable can go anywhere a literal constant is allowed. To use one as a table name or another identifier, wrap it in IDENTIFIER($my_table_name). String and binary variables are limited to 16KB. SHOW VARIABLES lists every variable in the current session, and UNSET drops one.

    Variables are private to the session that set them. Another session, even one opened by the same user, cannot read them. When the session closes, all of its variables are dropped. So a SET my_threshold = 100; in a worksheet is visible only in that worksheet's session and disappears when the session ends. For a value that has to persist or be shared, use a table or a parameter.

    Checkpoint 2 of 5· Check yourself

    An analyst runs SET my_threshold = 100; in one worksheet. Later, the same user opens a second session and runs SELECT $my_threshold; while the first session is still open. What happens, and what should the analyst use instead if several sessions need the value?

    Sources3

    3.Three parameter types and the levels each can be set at

    Parameters control how the account, sessions and objects behave. Every parameter has a default value. There are three types, and a parameter's type decides where you can override it.

    Parameter types, where they can be set, and the commands that set them
    TypeLevels it can be set atCommands
    Account parameterAccount onlyALTER ACCOUNT
    Session parameterAccount, then User, then SessionALTER ACCOUNT, ALTER USER, ALTER SESSION
    Object parameterAccount, then ObjectALTER ACCOUNT, CREATE <object> or ALTER <object>

    Most parameters are session parameters, such as DATE_OUTPUT_FORMAT, TIMEZONE and QUERY_TAG. An account administrator sets the account-wide default. An administrator can override it for one user with ALTER USER, and users can do the same for themselves. Any user can override it for the current session with ALTER SESSION.

    Object parameters attach to particular object types. Here are some, with the objects each can be set on:

    • DATA_RETENTION_TIME_IN_DAYS: database, schema and table.
    • PIPE_EXECUTION_PAUSED: schema and pipe.
    • LOG_LEVEL: from the account down to individual stored procedures and functions.
    • MAX_CONCURRENCY_LEVEL: warehouse.
    • STATEMENT_TIMEOUT_IN_SECONDS: warehouse. It is also a session parameter, so it can be set on a warehouse and in a session.

    Checkpoint 3 of 5· Match them up

    Match each parameter type to the levels where it can be set and the commands that set it

    Tap a term, then the definition that fits it.

    Sources45

    4.Precedence: the most specific level wins

    When the same parameter is set at more than one level, the most specific setting wins. For a session parameter, the account value is the default for each user, the user value is the default for each session that user starts, and an ALTER SESSION value overrides both for the current session. In the example above the session's 300 seconds applies, and other users' sessions keep the account's 3600. NETWORK_POLICY works the same way: if it is set on both the account and a user, the user's policy wins.

    Object parameters follow the same rule. An account-level value is the default for new objects. A value set in CREATE or ALTER on a particular object overrides the default for that object. For example, if the account's DATA_RETENTION_TIME_IN_DAYS is 1 and you run CREATE DATABASE sales DATA_RETENTION_TIME_IN_DAYS = 7, tables in sales get 7 unless a schema or table sets its own value, and tables in databases that set nothing still get 1.

    SHOW PARAMETERS tells you where a value came from. The value column shows the current setting and the level column shows where it was set. An empty level means the parameter has never been set, so the default applies. The command's scope also matters. With no IN clause it lists only session parameters. To see object parameters, add an IN clause with an object type and name. To see everything, add IN ACCOUNT. If you use LIKE, it has to come before IN.

    Setting an account-level default and confirming its levelsql
    ALTER ACCOUNT SET DATE_OUTPUT_FORMAT = 'DD/MM/YYYY'; SHOW PARAMETERS LIKE 'DATE_OUTPUT%' IN ACCOUNT;

    Here the level column shows ACCOUNT and the value is DD/MM/YYYY. That value is only the starting point for sessions, though. A user or session can still override it. ALTER ACCOUNT UNSET DATE_OUTPUT_FORMAT restores the default.

    Checkpoint 4 of 5· Check yourself

    A security administrator assigns network policy corp_vpn to the account and assigns network policy contractor_ips to one contractor's user. When that contractor signs in, which policy applies?

    Checkpoint 5 of 5· Fill the gap

    After setting an account-wide default, you want SHOW PARAMETERS to search all parameters, including account and object parameters, not just session parameters. Which keyword completes the IN clause?

    ALTER ACCOUNT SET DATE_OUTPUT_FORMAT = 'DD/MM/YYYY'; SHOW PARAMETERS LIKE 'DATE_OUTPUT%' IN  ? ;

    Sources564

    Practise it for real

    Create session variables, then find where parameter values come from

    1. 1.Run SET (min, max)=(40, 70); and then SELECT $min;

      Why: Shows that a variable can be used anywhere a literal can, as long as it has the $ prefix.

      You should see: The query returns 40.

    2. 2.Run SHOW VARIABLES;

      Why: Lists the variables in the current session and the names Snowflake stored them under.

      You should see: Two rows, MAX with 70 and MIN with 40, both stored in uppercase.

    3. 3.Run SHOW PARAMETERS LIKE '%time%';

      Why: With no IN clause, the command lists only session parameters.

      You should see: Session parameters whose names contain TIME. The level column is blank for any that have not been explicitly set.

    4. 4.Run SHOW PARAMETERS IN DATABASE mydb; using one of your own databases.

      Why: Object parameters appear only when you name an object.

      You should see: Object parameters such as DATA_RETENTION_TIME_IN_DAYS, each with its value and the level where it was set.

    Stuck? Get a nudge

    If the IN DATABASE output shows a level for DATA_RETENTION_TIME_IN_DAYS, check whether the value was set on the database itself or inherited from the account.

    Sources

    (6)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Specifies the schema to use in the session (specified schema must be in the current database for the session).”
      ↩︎ Session context: role, warehouse, database and schema
      “Specifies the primary role to use in the session.”
      ↩︎ Session context: role, warehouse, database and schema
    2. 2.
      “the namespace is inferred from the current database and schema in use for the session.”
      ↩︎ Session context: role, warehouse, database and schema
      “If a database and schema are not in use for the session, the namespace must be explicitly specified”
      ↩︎ Session context: role, warehouse, database and schema
      “If a database and schema are not in use for the session, the namespace must be explicitly specified when performing any operations on the objects.”
      ↩︎ Checkpoint
    3. 3.
      “To distinguish them from bind values and column names, all variables must be prefixed with a $ sign.”
      ↩︎ SQL variables last only as long as the session
      “To use a variable as an identifier, you must wrap it inside IDENTIFIER()”
      ↩︎ SQL variables last only as long as the session
      “The size of string or binary variables is limited to 16KB.”
      ↩︎ SQL variables last only as long as the session
      “SQL variables are private to a session. When a Snowflake session is closed, all variables created during the session are dropped.”
      ↩︎ Exam trap 1
      “In this example, the output is NULL because Snowflake stores variables with all uppercase letters.”
      ↩︎ Prediction
      “SQL variables are private to a session. When a Snowflake session is closed, all variables created during the session are dropped.”
      ↩︎ Checkpoint
    4. 4.
      “Session parameters can be set at the account, user, and session level.”
      ↩︎ Three parameter types and the levels each can be set at
      “Object parameters can be set at the account and object level.”
      ↩︎ Three parameter types and the levels each can be set at
      “If a parameter has been explicitly set, the output of this command also shows the level at which the parameter has been set.”
      ↩︎ Precedence: the most specific level wins
    5. 5.
      “You can only set account parameters at the account level”
      ↩︎ Three parameter types and the levels each can be set at
      “Also a session parameter (can be set at both the object and session levels).”
      ↩︎ Three parameter types and the levels each can be set at
      “The values that you set for a user become the default values in any session started by that user.”
      ↩︎ Precedence: the most specific level wins
      “Users can run the ALTER SESSION command to override session parameters for the current session.”
      ↩︎ Precedence: the most specific level wins
      “Users with the appropriate privileges can run the CREATE <object> or ALTER <object> commands to override object parameters for an individual object.”
      ↩︎ Precedence: the most specific level wins
      “By default, the command displays only session parameters:”
      ↩︎ Exam trap 2
      “If this parameter is set on the account and a user in the same account, the user-level network policy overrides the account-level network policy.”
      ↩︎ Exam trap 3
      “If this parameter is set on the account and a user in the same account, the user-level network policy overrides the account-level network policy.”
      ↩︎ Checkpoint
    6. 6.
      “If the level column is empty for a parameter, the parameter is not explicitly set and the current value is the default value.”
      ↩︎ Precedence: the most specific level wins
      “this date display format is only the default and can be overridden for any individual user or session.”
      ↩︎ Precedence: the most specific level wins

    Ready to test yourself?

    Practise the 21 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.