DAA-C01 Question 229
Single answerSet the contexts (e.g., database, schema, virtual warehouse, role)A data analyst connects to Snowflake using a BI tool that opens new sessions frequently. The analyst must query tables in the ANALYTICS_DB.REPORTING schema using the ANALYST_ROLE and run the queries on the BI_WH warehouse. The team wants to minimize failed queries caused by missing session context and avoid relying on fully qualified object names in every statement. Which action should the analyst take at the start of each new session to ensure the correct execution context is set?
- A
Execute: USE ROLE ANALYST_ROLE; USE WAREHOUSE BI_WH; USE DATABASE ANALYTICS_DB; USE SCHEMA REPORTING;
- B
Execute: ALTER USER SET DEFAULT_ROLE = ANALYST_ROLE, DEFAULT_WAREHOUSE = BI_WH, DEFAULT_NAMESPACE = ANALYTICS_DB.REPORTING;
- C
Execute only: USE DATABASE ANALYTICS_DB; because setting the database automatically sets the schema and warehouse for the session.
- D
Execute: SET ROLE = ANALYST_ROLE; SET WAREHOUSE = BI_WH; SET DATABASE = ANALYTICS_DB; SET SCHEMA = REPORTING;
Show answer and explanation
Correct answer: A
Explanation
Snowflake session context determines how unqualified SQL statements are interpreted and where compute is consumed. For data analysts working through BI tools that create many short-lived sessions, explicitly setting session context at the beginning of each session is a practical best practice when defaults cannot be guaranteed. The correct commands are USE ROLE, USE WAREHOUSE, USE DATABASE, and USE SCHEMA. These commands define the active security role, the virtual warehouse used for compute, and the current namespace for object resolution. While administrators can configure user-level defaults such as default role, default warehouse, and default namespace to reduce setup needs, those defaults apply when a session starts and are not substitutes for explicitly correcting context inside a session when needed. This aligns with Snowflake documentation on session context and SQL command syntax for USE commands.
- A. Correct.
Correct. In Snowflake, session context for role, warehouse, database, and schema is established with USE commands such as USE ROLE, USE WAREHOUSE, USE DATABASE, and USE SCHEMA. This is the appropriate way to initialize each new session so unqualified object references resolve correctly and queries run on the intended virtual warehouse.
- B. Incorrect.
Incorrect. ALTER USER can be used by an authorized administrator to define defaults for future sessions, but it is not a command an analyst would typically execute at the start of each session. Also, the syntax shown is incomplete and misleading because ALTER USER must target a specific user and requires the proper administrative privileges. The question asks what to do at the start of each new session, not how an administrator could configure account-level defaults.
- C. Incorrect.
Incorrect. USE DATABASE sets only the current database. It does not automatically set the warehouse, and although it can affect namespace resolution, it does not guarantee the desired schema is selected unless explicitly set or unless the user's default namespace already matches. Relying on this would still lead to failures or unexpected object resolution in many BI-tool sessions.
- D. Incorrect.
Incorrect. Snowflake uses USE commands, not generic SET ROLE, SET WAREHOUSE, SET DATABASE, or SET SCHEMA statements, to establish these session contexts. SET in Snowflake is used for session variables, not for changing the active role, warehouse, database, or schema.