Snowflake SnowPro Core COF-C03 Practice Test Questions and Exam Dumps Part13 Q241-260

View Full Snowflake SnowPro Core COF-C03 Exam Dumps and Practice Test Dumps.

 

Question 241

Which Snowflake command can be used to change the current database for a session?

  1. USE DATABASE
  2. SET DATABASE
  3. ALTER DATABASE
  4. SWITCH DATABASE

Correct Answer: 1

Explanation

USE DATABASE changes the current database for the active Snowflake session. Once a database is selected, object names that are not fully qualified can be resolved relative to that database and the current schema. This command is useful when users work repeatedly with objects inside a particular database and want to avoid specifying the database name in every statement. ALTER DATABASE serves a different purpose by modifying database properties. SET DATABASE and SWITCH DATABASE are not the standard Snowflake commands for selecting the current database.

Question 242

What does the CURRENT_SCHEMA() function return?

  1. The current user’s default role
  2. The schema currently active in the session
  3. The most recently created schema
  4. The database owner’s schema

Correct Answer: 2

Explanation

CURRENT_SCHEMA() returns the schema currently active in the Snowflake session. The current schema determines where unqualified object references can be resolved when a database is also appropriately selected. This function can be useful in SQL statements, scripts, and troubleshooting situations where users need to determine the session’s current context. It does not return the user’s role or identify the most recently created schema. Session context functions such as CURRENT_DATABASE(), CURRENT_SCHEMA(), and CURRENT_ROLE() provide information about the environment in which SQL statements are executing.

Question 243

Which function returns the name of the role currently active in a Snowflake session?

  1. CURRENT_USER()
  2. CURRENT_DATABASE()
  3. CURRENT_ROLE()
  4. CURRENT_WAREHOUSE()

Correct Answer: 3

Explanation

CURRENT_ROLE() returns the name of the role currently active in the Snowflake session. The active role determines which privileges are available when executing operations, subject to Snowflake’s authorization model and any enabled secondary roles. CURRENT_USER() identifies the current user, CURRENT_DATABASE() identifies the current database, and CURRENT_WAREHOUSE() identifies the current warehouse. Checking CURRENT_ROLE() can be useful when troubleshooting access problems because a user may possess a privilege through one role while another role is currently active for the session.

Question 244

Which function returns the username associated with the current Snowflake session?

  1. CURRENT_ROLE()
  2. CURRENT_SCHEMA()
  3. CURRENT_DATABASE()
  4. CURRENT_USER()

Correct Answer: 4

Explanation

CURRENT_USER() returns the name of the user associated with the current Snowflake session. It can be useful in SQL statements, auditing logic, troubleshooting, and security-related expressions where the identity executing the statement needs to be identified. CURRENT_ROLE() instead identifies the active role, while CURRENT_DATABASE() and CURRENT_SCHEMA() report session object context. Because users and roles represent different security concepts, checking CURRENT_USER() does not tell you which role is currently providing authorization. Both identity and active-role context can be relevant when diagnosing access behavior.

Question 245

Which Snowflake function returns the current timestamp according to the session’s time zone?

  1. CURRENT_TIMESTAMP()
  2. CURRENT_DATE()
  3. CURRENT_TIME()
  4. CURRENT_ROLE()

Correct Answer: 1

Explanation

CURRENT_TIMESTAMP() returns the current timestamp, with the result reflecting Snowflake’s timestamp and session time-zone semantics. It is commonly used when a query needs the current date and time rather than only a date or only a time. CURRENT_DATE() returns the current date, while CURRENT_TIME() returns the current time. CURRENT_ROLE() is unrelated because it identifies the active authorization role. Session time-zone settings can influence how timestamp values are displayed, making it important to understand timestamp types and session context when working with time-sensitive applications.

Question 246

Which function returns the current calendar date without requiring a timestamp value?

  1. CURRENT_TIME()
  2. CURRENT_DATE()
  3. CURRENT_ROLE()
  4. CURRENT_SCHEMA()

Correct Answer: 2

Explanation

CURRENT_DATE() returns the current calendar date for the session. It is useful when SQL logic requires today’s date without the time-of-day component. Common applications include filtering records by the current date, calculating date intervals, or generating date-based reports. CURRENT_TIME() returns a time value rather than a date, while CURRENT_ROLE() and CURRENT_SCHEMA() provide session security and object-context information. Using CURRENT_DATE() instead of a timestamp function can make SQL expressions clearer when hours, minutes, and seconds are not relevant to the business requirement.

Question 247

Which function can calculate the difference between two date or time values using a specified unit?

  1. DATEADD
  2. DATEDIFF
  3. DATE_TRUNC
  4. TO_DATE

Correct Answer: 2

Explanation

DATEDIFF calculates the difference between two date or time expressions using a specified unit such as day, month, or year. It is useful when queries need to determine elapsed periods between events, such as the number of days between an order date and delivery date. DATEADD performs the opposite type of operation by adding an interval to a date or timestamp. DATE_TRUNC reduces a temporal value to a specified precision, while TO_DATE converts or interprets values as dates. Selecting the correct function depends on whether the requirement is difference, addition, truncation, or conversion.

Question 248

Which function adds a specified interval to a date or timestamp?

  1. DATEDIFF
  2. DATE_TRUNC
  3. DATEADD
  4. EXTRACT

Correct Answer: 3

Explanation

DATEADD adds a specified amount of time to a date, time, or timestamp expression. The interval can use supported units such as days, months, hours, or other temporal components depending on the expression and operation. This function is useful for calculations such as determining a future due date or moving a timestamp by a defined period. DATEDIFF calculates the difference between temporal values, while DATE_TRUNC changes a value to a specified precision and EXTRACT retrieves individual components. DATEADD is therefore appropriate when a temporal value needs to be shifted forward or backward.

Question 249

Which function can truncate a timestamp to a specified precision such as month or day?

  1. DATE_TRUNC
  2. DATEDIFF
  3. DATEADD
  4. CURRENT_TIME

Correct Answer: 1

Explanation

DATE_TRUNC truncates a date or timestamp to a specified time unit. For example, a timestamp can be truncated to the beginning of its month, day, or another supported period. This is particularly useful for reporting and aggregation because values can be normalized to common calendar boundaries before grouping. DATEADD changes a temporal value by adding an interval, while DATEDIFF calculates differences between temporal values. CURRENT_TIME provides the current time rather than transforming an existing timestamp. DATE_TRUNC is therefore useful when temporal precision needs to be reduced consistently.

Question 250

Which conversion function can explicitly convert a value to a DATE data type?

  1. CAST
  2. FLATTEN
  3. SPLIT
  4. OBJECT_KEYS

Correct Answer: 1

Explanation

CAST explicitly converts an expression from one data type to another when the conversion is supported. For example, a value can be cast to DATE when the source value is compatible with Snowflake’s conversion rules. Explicit casting is useful when SQL expressions require a particular data type for comparisons, calculations, or function arguments. FLATTEN works with semi-structured data, SPLIT separates strings into arrays, and OBJECT_KEYS returns keys from objects. CAST therefore provides a general mechanism for requesting a specific target data type.

Question 251

Which Snowflake function can safely attempt a conversion and return NULL instead of raising an error when conversion fails?

  1. TRY_CAST
  2. CAST
  3. CONVERT_ONLY
  4. FORCE_CAST

Correct Answer: 1

Explanation

TRY_CAST attempts to convert a value to a specified data type and returns NULL when the conversion cannot be performed successfully. This behavior is useful when processing data that may contain invalid or inconsistent values and where a single conversion failure should not terminate the entire query. CAST, by contrast, can produce an error when the supplied value cannot be converted according to the applicable rules. TRY_CAST is therefore particularly helpful in data cleansing, ingestion validation, and analytical queries where invalid values need to be handled gracefully.

Question 252

What does the NULLIF function return when its two input expressions are equal?

  1. The first expression
  2. The second expression
  3. An empty string
  4. NULL

Correct Answer: 4

Explanation

NULLIF compares two expressions and returns NULL when the two expressions are equal. If they are not equal, it returns the first expression. This makes NULLIF useful for converting particular values into NULL when those values should be treated as missing or excluded from subsequent calculations. For example, it can help avoid treating a designated placeholder value as meaningful data. COALESCE has a different purpose because it returns the first non-NULL expression from its arguments. Understanding these functions helps with controlled NULL handling in Snowflake SQL.

Question 253

Which function returns the first expression that is not NULL from a list of expressions?

  1. COALESCE
  2. NULLIF
  3. NVL2
  4. DECODE

Correct Answer: 1

Explanation

COALESCE evaluates its expressions and returns the first one that is not NULL. It can accept multiple expressions, making it useful when several fallback values are available. For example, a query might use a preferred customer field first and then fall back to another field if the preferred value is missing. NULLIF instead produces NULL when two expressions are equal. NVL2 evaluates whether an expression is NULL and chooses between two alternatives. COALESCE is therefore the appropriate function when multiple possible non-NULL values need to be considered in sequence.

Question 254

Which SQL clause is used to group rows so aggregate functions can calculate results for each group?

  1. ORDER BY
  2. GROUP BY
  3. LIMIT
  4. DISTINCT

Correct Answer: 2

Explanation

GROUP BY divides rows into groups based on one or more expressions, allowing aggregate functions such as SUM, COUNT, AVG, MIN, and MAX to calculate results for each group. For example, sales data can be grouped by region before calculating total sales for each region. ORDER BY controls result ordering, LIMIT restricts the number of returned rows, and DISTINCT removes duplicate result rows. GROUP BY is therefore central to analytical SQL when summaries are required across categories, dimensions, or other grouping attributes.

Question 255

Which SQL clause filters grouped results after aggregate calculations are performed?

  1. WHERE
  2. FROM
  3. HAVING
  4. GROUP

Correct Answer: 3

Explanation

HAVING filters groups after GROUP BY and aggregate calculations have been applied. It is useful when the filtering condition depends on an aggregate result, such as selecting departments whose total sales exceed a particular threshold. WHERE generally filters individual rows before grouping occurs, making it appropriate for row-level conditions. FROM identifies the source of the data, while GROUP is not the standard standalone clause for filtering grouped results. Understanding the distinction between WHERE and HAVING is important when constructing queries that combine row filtering with aggregate analysis.

Question 256

Which clause determines the order in which rows are returned by a query?

  1. GROUP BY
  2. WHERE
  3. ORDER BY
  4. HAVING

Correct Answer: 3

Explanation

ORDER BY specifies the sorting order of rows returned by a query. It can sort results using one or more expressions and can specify ascending or descending ordering. This is useful when reports require results to appear in a particular sequence, such as highest revenue first or dates from oldest to newest. WHERE filters rows, GROUP BY creates groups for aggregation, and HAVING filters grouped results. ORDER BY affects presentation and result ordering rather than determining which rows are eligible for inclusion in the query.

Question 257

Which set operator returns rows that appear in either query result while removing duplicate rows?

  1. UNION
  2. UNION ALL
  3. INTERSECT
  4. MINUS

Correct Answer: 1

Explanation

UNION combines the results of two compatible queries and removes duplicate rows from the combined result. The participating queries must produce compatible numbers and types of columns. UNION ALL also combines query results but preserves duplicate rows, which can be useful when duplicates are meaningful or when avoiding the additional duplicate-elimination operation is desirable. INTERSECT returns rows common to both result sets, while MINUS returns rows present in one result but not the other. Choosing the correct set operator depends on how overlapping results should be handled.

Question 258

Which set operator preserves duplicate rows when combining the results of two queries?

  1. UNION
  2. INTERSECT
  3. MINUS
  4. UNION ALL

Correct Answer: 4

Explanation

UNION ALL combines the results of two compatible queries while preserving duplicate rows. This differs from UNION, which removes duplicate rows from the combined result. Preserving duplicates can be important when each source occurrence represents a meaningful event or when the user wants straightforward concatenation without duplicate elimination. INTERSECT returns common rows, while MINUS returns rows from one result that are not present in the other. Understanding these differences helps prevent accidental removal or retention of duplicate records during SQL result-set operations.

Question 259

Which join returns only rows where the join condition finds a matching row in both input tables?

  1. LEFT JOIN
  2. INNER JOIN
  3. FULL OUTER JOIN
  4. CROSS JOIN

Correct Answer: 2

Explanation

An INNER JOIN returns rows for which the join condition matches records from both participating tables. Rows without a corresponding match on either side are excluded from the result. This makes INNER JOIN useful when analysis requires only records that have relationships represented in both datasets. LEFT JOIN preserves all rows from the left side, FULL OUTER JOIN preserves unmatched rows from both sides, and CROSS JOIN produces combinations between rows. Choosing INNER JOIN is appropriate when unmatched records should not appear in the query result.

Question 260

Which join preserves all rows from the left table even when no matching row exists in the right table?

  1. INNER JOIN
  2. CROSS JOIN
  3. LEFT OUTER JOIN
  4. NATURAL JOIN

Correct Answer: 3

Explanation

LEFT OUTER JOIN preserves every row from the left input table and includes matching rows from the right table when the join condition succeeds. When no right-side match exists, the columns originating from the right table are represented with NULL values. This behavior is useful when the analysis must retain all primary records while optionally adding related information. INNER JOIN would remove unmatched left-side rows, while CROSS JOIN creates combinations without a matching condition. LEFT OUTER JOIN is therefore suitable for completeness-focused reporting and relationship analysis.