What you will be able to do
- Set the session's role, warehouse, database and schema with USE, and check them with the context functions
- Read column types, nullability, row counts and sizes from SHOW, DESCRIBE and INFORMATION_SCHEMA without scanning table data
- Judge how far to trust the statistics Snowflake maintains, and compare them across tables to decide which joins, aggregations or filters a business goal requires
- Turn a business question into a list of columns, then use COUNT to measure null rates and cardinality
Key concept
Metadata-first discovery — Snowflake keeps metadata about every object: its columns and their types, nullability, row count and size. You read that metadata first, with SHOW, DESCRIBE and INFORMATION_SCHEMA, and only then write queries that scan the data to profile the columns the question needs.
1.Session context decides what you are looking at
Data discovery means finding out what a dataset holds before you build anything on it. That starts before the first query against the data. Every Snowflake session runs as a role, on a warehouse, pointed at a database and schema, and those four settings decide which objects you see and what the metadata tells you about them. The USE command sets each one for the current session: USE ROLE, USE WAREHOUSE, USE DATABASE and USE SCHEMA, plus USE SECONDARY ROLES for the roles that are active alongside the primary one.
Context changes the answers metadata gives you. The Information Schema TABLES view returns a row for each table and view in the database you name, or in the current database if you name none. So the same metadata query lists different tables after USE DATABASE points somewhere else. The role matters as well. Describing a dynamic table without the MONITOR privilege, or a privilege that includes it, hides some of its metadata. When a table you expected is missing, or a metadata column comes back blank, check the session context before you decide the data isn't there.
Checking takes one query. Each context function returns the value the session is using right now. Run it at the top of a discovery worksheet so every later result is read in the right context:
SELECT CURRENT_ROLE(),
CURRENT_SECONDARY_ROLES(),
CURRENT_WAREHOUSE(),
CURRENT_DATABASE(),
CURRENT_SCHEMA();Checkpoint 1 of 4· Fill the gap
You open a discovery worksheet and want to confirm which warehouse the session is running on before reading any metadata. Which function completes the context query?
SELECT CURRENT_ROLE(),
CURRENT_SECONDARY_ROLES(),
? (),
CURRENT_DATABASE(),
CURRENT_SCHEMA();Each context function in the CURRENT_*() family reads one setting the session is using right now, and CURRENT_WAREHOUSE() returns the active warehouse. USE WAREHOUSE changes that setting, and CURRENT_WAREHOUSE() reads it.
Source: docs.snowflake.com2.Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA
Snowflake can answer "what is in this table?" from metadata, so you can learn column types, nullability and table size without scanning a single row. Three tools share the job:
SHOWfollowed by an object type lists the existing objects of that type, as inSHOW TABLES,SHOW VIEWSorSHOW WAREHOUSES. Its output includes common properties (name, creation timestamp, owning role, comment) and properties specific to that object type. For tables, these includerowsandbytes.DESCRIBEfollowed by an object type and name, which can be shortened toDESC, gives the details of one object. For a table, the defaultTYPE = COLUMNSreturns one row per column.- Information Schema views, such as
TABLES, are ordinary views you query with SQL.TABLEShas one row per table or view, withTABLE_TYPE,ROW_COUNT,BYTES(the bytes a scan of the table would read) andCREATED.
CREATE OR REPLACE TABLE desc_example(
c1 INT PRIMARY KEY,
c2 INT,
c3 INT UNIQUE,
c4 VARCHAR(30) DEFAULT 'Not applicable' COMMENT 'This column is rarely populated',
c5 VARCHAR(100));| name | type | null? | default | primary key | unique key |
|---|---|---|---|---|---|
| C1 | NUMBER(38,0) | N | NULL | Y | N |
| C2 | NUMBER(38,0) | Y | NULL | N | N |
| C3 | NUMBER(38,0) | Y | NULL | N | Y |
| C4 | VARCHAR(30) | Y | 'Not applicable' | N | N |
The output shows that INT is stored as NUMBER(38,0), and that the primary key column C1 reports null? = N. The key flags come from the table's declared constraints, and what those constraints do and don't guarantee is covered under data integrity constraints.
Three details catch people out. First, DESCRIBE TABLE does not show a table's object parameters; use SHOW PARAMETERS IN TABLE for those. Second, DESCRIBE TABLE and DESCRIBE VIEW are interchangeable, but DESC VIEW leaves out the view definition, which SHOW VIEWS returns. Third, you can filter or trim SHOW and DESCRIBE output with the pipe operator (->>) or RESULT_SCAN. The output column names are lowercase, so you have to double-quote them, as in SELECT "type". An unquoted type does not match.
Snowflake maintains statistics on tables and views, and they are the cheapest evidence you have about what a dataset holds. They are why a simple query such as COUNT(*) returns quickly instead of reading every row. A row access policy takes that shortcut away: with a policy on the table, Snowflake must scan each row and decide whether the user may see it, so the same count runs slower.
Each statistic answers a narrower question than its name suggests:
BYTESis what a scan would read, so summing it does not give storage cost. Time Travel and Fail-safe usage are left out.LAST_ALTEREDmoves on DDL, on DML even when no rows change, and on background metadata maintenance. For the last modification time of a table or view, readLAST_DDL.- On hybrid tables, row count and bytes are approximate. Right after a load they can read NULL until a periodic background compaction updates them, and
SELECT COUNT(*)gives an accurate count in the meantime. INFORMATION_SCHEMA.TABLESshows only objects the current role has privileges on, and theACCOUNT_USAGETABLESview can lag by up to 90 minutes.
Comparing statistics across tables shows whether the data elements a business goal needs exist at the level of data granularity the BI report or SQL analysis asks for. Take an orders table with a ROW_COUNT of 50,000 and an order_lines table with 210,000. The lines sit at a finer grain, so a report counting orders per region either reads orders alone or aggregates the lines first. Joining the two and then counting rows inflates every total, because an inner join produces a row for each matching line.
That comparison is where you evaluate which transformations are required, before writing any of them. Elements spread across two tables call for table joins. A table finer than the report calls for an aggregation. A table holding more history or more regions than the goal covers calls for a filter.
Checkpoint 2 of 4· Check yourself
Before profiling anything, an analyst wants one result that lists every table in the current schema, with each table's owning role, creation timestamp and row count, without scanning any table data. Which command does this?
SHOW TABLES lists all existing tables from metadata. Its output includes common properties such as name, creation timestamp and owning role, and for tables it also includes rows and bytes. DESCRIBE TABLE covers only one table and returns one row per column. SHOW PARAMETERS IN TABLE returns a table's object parameters. COUNT(*) scans the data and does not give ownership or creation time.
“Common properties (name, creation timestamp, owning role, comment, etc.)”Source: docs.snowflake.com
Checkpoint 3 of 4· Check yourself
Just after a large load into a hybrid table, SHOW HYBRID TABLES reports NULL in the rows column. The analyst needs an accurate row count now. What should they do?
A periodic background compaction fills in the rows and bytes statistics for hybrid tables, and after a large load that can take a long time. SELECT COUNT(*) counts the rows directly, so it is accurate now. DESCRIBE TABLE returns columns, not a row count.
“In the meantime, you can run a SELECT COUNT(*) query on the table to get an accurate row count.”Source: docs.snowflake.com
3.Profiling the columns a business question needs
A business question tells you which columns you need. "Monthly order count per region" needs a region column, an order date and something that identifies an order. "Which postal codes have both a sales office and a customer?" needs postal_code from two tables. The list is the same whether the question comes as a SQL request or as an existing BI report: the report's groupings, filters and measures are the columns to check. For each one, discovery confirms three things: the column exists, its type can be used as it is, and it is filled in well enough to answer the question.
DESCRIBE covers the first two. type shows whether a date is stored as DATE or as text. null? = Y means only that the column allows NULLs, not how many it actually holds. To measure how complete a column is, you have to run a query.
COUNT gives you two profiles in one query. COUNT(*) returns the total number of records and COUNT(col) returns the non-NULL ones, so 1 - COUNT(col) / COUNT(*) is the column's null rate. COUNT(DISTINCT col) gives its cardinality. It also accepts several columns, so COUNT(DISTINCT last_name, first_name) counts distinct combinations. That makes it the test for a candidate key: if COUNT(DISTINCT order_id) equals COUNT(*), every row has its own order_id.
Act on what the numbers show. A region column that is 15% NULL means the regional report needs an explicit "unknown" bucket or a different source column. Better to find that out now than when a dashboard total fails to reconcile. Compare COUNT(*) with the ROW_COUNT that metadata reports to confirm you are profiling the whole table and not a filtered subset.
Checkpoint 4 of 4· Check yourself
A stakeholder asks: "Which postal codes have both a sales office and a customer?" The data sits in two tables: sales_office_postal_example (office_name, postal_code) and customer_postal_example (customer, postal_code). Which columns should discovery check for existence, usable type and completeness before any query is written?
The business question decides which columns to profile. This question compares postal codes across offices and customers, so it needs postal_code from both tables. The name columns do not affect the answer, and profiling every column wastes effort on data the question never uses.
“One table records the postal code of each sales office, and the other records the postal code of each customer.”Source: docs.snowflake.com
Sources7
Sources
(12)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.snowflake.com/en/sql-reference/sql/useOfficial docs
“Specifies the role, warehouse, database, or schema to use for the current session.”
↩︎ Session context decides what you are looking at“To view the current role, secondary roles, database, schema, and warehouse for the session, use the corresponding context functions.”
↩︎ Session context decides what you are looking at - 2.
“This Information Schema view displays a row for each table and view in the specified (or current) database”
↩︎ Session context decides what you are looking at“Number of rows in the table.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“Querying the sum(bytes) for a table does not represent the total storage usage, because the amount does not include Time Travel and Fail-safe usage.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“This column is updated even when no rows are affected by the DML statement.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“For views and tables, use the LAST_DDL column for the last modification time for an object.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“The view only displays objects for which the current role for the session has been granted access privileges.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“This Information Schema view displays a row for each table and view in the specified (or current) database”
↩︎ Key concept“Querying the sum(bytes) for a table does not represent the total storage usage, because the amount does not include Time Travel and Fail-safe usage.”
↩︎ Exam trap 2 - 3.
“Without MONITOR or a privilege that includes it, some metadata is hidden.”
↩︎ Session context decides what you are looking at - 4.https://docs.snowflake.com/en/sql-reference/sql/showOfficial docs
“Lists the existing objects for the specified object type.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“Common properties (name, creation timestamp, owning role, comment, etc.)”
↩︎ Checkpoint - 5.https://docs.snowflake.com/en/sql-reference/sql/descOfficial docs
“DESCRIBE can be abbreviated to DESC.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA - 6.
“DESCRIBE TABLE and DESCRIBE VIEW are interchangeable.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“You must use double-quoted identifiers because the output column names for SHOW commands are in lowercase.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“This command does not show the object parameters for a table. Instead, use SHOW PARAMETERS IN TABLE.”
↩︎ Exam trap 1“Whether the column accepts NULL values (Y or N).”
↩︎ Exam trap 3 - 7.
“Snowflake maintains statistics on tables and views, and this optimization allows simple queries to run faster.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“Snowflake must scan each row and determine whether the user is allowed to view the row.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“Returns either the number of non-NULL records for the specified columns, or the total number of records.”
↩︎ Profiling the columns a business question needs“you could count the number of distinct combinations of last name and first name.”
↩︎ Profiling the columns a business question needs - 8.
“Just as with SHOW TABLES and SHOW HYBRID TABLES, the bytes and row count are approximate.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA - 9.
“a background compaction operation runs periodically and updates these statistics.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA“In the meantime, you can run a SELECT COUNT(*) query on the table to get an accurate row count.”
↩︎ Checkpoint - 10.
“Latency for the view may be up to 90 minutes.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA - 11.
“For each row of o1, a row is produced for each row of o2 that matches according to the ON condition subclause.”
↩︎ Reading metadata with SHOW, DESCRIBE and INFORMATION_SCHEMA
Also cited
“One table records the postal code of each sales office, and the other records the postal code of each customer.”
↩︎ Checkpoint