Snowflake Data Cloud
Hands-on • Paste into a Snowsight worksheet

Snowflake Hands-on SQL Lab

Ten short exercises that make the concepts from the modules visible in a real account. Nothing needs external files or cloud credentials. The lab generates its own data and costs well under one credit on a trial.

0 of 10 steps done
00

Before you start

  • A Snowflake trial account (Enterprise edition recommended). See setup on the hub.
  • In Snowsight, open Projects → Worksheets → + SQL Worksheet. Run one statement with Ctrl/Cmd + Enter or everything with Ctrl/Cmd + Shift + Enter.
  • Keep the Query Profile handy: in the results pane, open Query Details → Query Profile, or go to Monitoring → Query History.
  • Tick each step when done. Progress is saved in this browser only.
A

Part A: Build data and watch the engine

1. Create your sandbox

A dedicated warehouse, database and schema so cleanup is a single statement at the end.

USE ROLE SYSADMIN;

CREATE WAREHOUSE IF NOT EXISTS lab_wh
  WAREHOUSE_SIZE = 'SMALL' AUTO_SUSPEND = 60 AUTO_RESUME = TRUE INITIALLY_SUSPENDED = TRUE;

CREATE DATABASE IF NOT EXISTS lab_db;
CREATE SCHEMA IF NOT EXISTS lab_db.sales;

USE WAREHOUSE lab_wh;
USE SCHEMA lab_db.sales;

2. Generate 50 million orders, twice

orders is written in random date order. orders_sorted holds the same rows written in date order. This takes about 1–2 minutes on a Small warehouse.

CREATE OR REPLACE TABLE orders AS
SELECT SEQ8()                                                   AS order_id,
       UNIFORM(1, 50000, RANDOM())                              AS customer_id,
       DATEADD(day, UNIFORM(0, 364, RANDOM()), '2026-01-01'::DATE) AS order_date,
       UNIFORM(500, 50000, RANDOM()) / 100                      AS amount,
       ARRAY_CONSTRUCT('NEW','SHIPPED','COMPLETE','RETURNED')[UNIFORM(0, 3, RANDOM())]::STRING AS status
FROM TABLE(GENERATOR(ROWCOUNT => 50000000));

CREATE OR REPLACE TABLE orders_sorted AS
SELECT * FROM orders ORDER BY order_date;

SELECT COUNT(*) FROM orders;   -- instant: answered from metadata, look at the profile

Observe: the COUNT(*) profile shows a METADATA-BASED RESULT with no table scan. That's the metadata cache from Module 02.

3. See pruning with your own eyes

ALTER SESSION SET USE_CACHED_RESULT = FALSE;   -- measure honestly

SELECT SUM(amount) FROM orders
WHERE order_date BETWEEN '2026-03-01' AND '2026-03-31';

SELECT SUM(amount) FROM orders_sorted
WHERE order_date BETWEEN '2026-03-01' AND '2026-03-31';

-- Compare the layout of the two tables for this column
SELECT SYSTEM$CLUSTERING_INFORMATION('orders',        '(order_date)');
SELECT SYSTEM$CLUSTERING_INFORMATION('orders_sorted', '(order_date)');

-- The pruning-killer: a function wrapped around the column
SELECT SUM(amount) FROM orders_sorted
WHERE TO_CHAR(order_date, 'YYYY-MM') = '2026-03';

Observe: in each profile, compare Partitions scanned with Partitions total. The random table scans almost all of them. The sorted table scans about one-twelfth. Compare average_depth in the two JSON results. Then check whether the TO_CHAR version still prunes as well as the BETWEEN version.

4. Watch the result cache and the warehouse cache

ALTER SESSION SET USE_CACHED_RESULT = TRUE;

SELECT status, COUNT(*), SUM(amount) FROM orders GROUP BY status;  -- run it
SELECT status, COUNT(*), SUM(amount) FROM orders GROUP BY status;  -- run it again

ALTER SESSION SET USE_CACHED_RESULT = FALSE;
SELECT status, COUNT(*), SUM(amount) FROM orders GROUP BY status;  -- warm warehouse cache

ALTER WAREHOUSE lab_wh SUSPEND;
SELECT status, COUNT(*), SUM(amount) FROM orders GROUP BY status;  -- cold again

Observe: the second run shows QUERY RESULT REUSE and takes milliseconds with no warehouse. The third run shows a high Percentage scanned from cache in the TableScan node. After suspend, that percentage drops back to around 0.

B

Part B: Load through a stage, then break and fix things

5. Stage round-trip: unload, list, load, re-load

An internal stage stands in for S3 or Azure. COPY works the same against an external stage.

CREATE OR REPLACE STAGE lab_stage FILE_FORMAT = (TYPE = PARQUET);

-- Unload January as Parquet files
COPY INTO @lab_stage/orders/
FROM (SELECT * FROM orders_sorted WHERE order_date < '2026-02-01')
HEADER = TRUE;

LIST @lab_stage/orders/;

-- Load them into a new table
CREATE OR REPLACE TABLE orders_jan LIKE orders;
COPY INTO orders_jan FROM @lab_stage/orders/ MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE;

-- Run the exact same COPY again
COPY INTO orders_jan FROM @lab_stage/orders/ MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE;

Observe: the second COPY reports Copy executed with 0 files processed. Load metadata remembers the files for 64 days, which is why re-running a load job is safe.

6. A bad DELETE, undone with Time Travel

SELECT COUNT(*) FROM orders_jan;

DELETE FROM orders_jan WHERE status = 'RETURNED';   -- "oops"
SET bad_query = LAST_QUERY_ID();

SELECT COUNT(*) FROM orders_jan;                                       -- fewer rows
SELECT COUNT(*) FROM orders_jan BEFORE (STATEMENT => $bad_query);      -- original count

-- Put back exactly the rows the bad statement removed
INSERT INTO orders_jan
SELECT * FROM orders_jan BEFORE (STATEMENT => $bad_query)
WHERE status = 'RETURNED';

SELECT COUNT(*) FROM orders_jan;                                       -- restored

7. DROP, UNDROP, and the CREATE OR REPLACE trap

DROP TABLE orders_jan;
UNDROP TABLE orders_jan;
SELECT COUNT(*) FROM orders_jan;      -- all back

-- The trap: CREATE OR REPLACE silently drops the old table
CREATE OR REPLACE TABLE orders_jan (order_id NUMBER);
SELECT COUNT(*) FROM orders_jan;      -- 0 rows!

SHOW TABLES HISTORY LIKE 'ORDERS_JAN';   -- note the dropped version

ALTER TABLE orders_jan RENAME TO orders_jan_mistake;
UNDROP TABLE orders_jan;
SELECT COUNT(*) FROM orders_jan;      -- the real data is back
DROP TABLE orders_jan_mistake;
C

Part C: Clone, build a pipeline, and check the bill

8. Zero-copy clone for a dev copy

CREATE OR REPLACE TABLE orders_dev CLONE orders_sorted;   -- 50M rows, instant

UPDATE orders_dev SET amount = amount * 1.10 WHERE order_date = '2026-01-01';

-- Source is untouched
SELECT 'prod' AS env, SUM(amount) FROM orders_sorted WHERE order_date = '2026-01-01'
UNION ALL
SELECT 'dev',        SUM(amount) FROM orders_dev    WHERE order_date = '2026-01-01';

-- Clone a whole schema as it was 5 minutes ago
CREATE OR REPLACE SCHEMA lab_db.sales_5min_ago CLONE lab_db.sales AT (OFFSET => -300)
  IGNORE TABLES WITH INSUFFICIENT DATA RETENTION;

Observe: the clone finishes in about a second regardless of size. Only the micro-partitions changed by the UPDATE are new storage. Tables created less than 5 minutes ago are skipped by the IGNORE TABLES clause instead of failing the clone. If the schema itself is younger than 5 minutes, the clone errors. Use OFFSET => -60 instead.

9. A dynamic table that keeps itself fresh

CREATE OR REPLACE DYNAMIC TABLE daily_revenue
  TARGET_LAG = '1 minute'
  WAREHOUSE  = lab_wh
AS
SELECT order_date, COUNT(*) AS orders, SUM(amount) AS revenue
FROM orders_jan
WHERE status = 'COMPLETE'
GROUP BY order_date;

SELECT * FROM daily_revenue ORDER BY order_date LIMIT 5;

-- New data arrives in the source...
INSERT INTO orders_jan (order_id, customer_id, order_date, amount, status)
VALUES (-1, 1, '2026-01-01', 1000000, 'COMPLETE');

-- ...wait 1-2 minutes, then:
SELECT * FROM daily_revenue WHERE order_date = '2026-01-01';

SHOW DYNAMIC TABLES LIKE 'DAILY_REVENUE';    -- check refresh_mode (INCREMENTAL?)
SELECT name, state, refresh_action, refresh_start_time
FROM TABLE(information_schema.dynamic_table_refresh_history(NAME => 'DAILY_REVENUE'))
ORDER BY refresh_start_time DESC;

ALTER DYNAMIC TABLE daily_revenue SUSPEND;   -- important: stop the 1-minute refreshes

10. See what the lab cost, then clean up

SELECT start_time, end_time, credits_used
FROM TABLE(information_schema.warehouse_metering_history(
       DATEADD('hour', -3, CURRENT_TIMESTAMP()), CURRENT_TIMESTAMP(), 'LAB_WH'))
ORDER BY start_time;

-- Clean up everything the lab created
ALTER SESSION UNSET USE_CACHED_RESULT;
DROP DATABASE IF EXISTS lab_db;      -- recoverable with UNDROP DATABASE for 1 day
DROP WAREHOUSE IF EXISTS lab_wh;

Done. You have now used every core concept an interviewer will ask about. Test yourself in the Q&A bank with interview mode on.

Hub