A quick tour of Snowsight
After you sign up, you land in Snowsight at app.snowflake.com. The left menu has many items; these are the ones you'll use in this course:
| Menu item | What it's for |
|---|---|
| Workspaces | Your SQL files and notebooks. Click + Add new β SQL file to start writing queries. (Older "worksheets" were moved here.) |
| Catalog β Database Explorer | Browse databases, schemas, tables and their columns; preview data |
| Ingestion | Upload a local file into a table with a few clicks; set up loading from cloud storage |
| Monitoring β Query History | Every query that ran: time, warehouse, and the Query Profile |
| Compute β Warehouses | Create, resize, suspend warehouses |
| Admin / Governance | Users, roles, cost management, policies |
At the top of a SQL file you pick the role and warehouse from drop-downs, and you can also set them in SQL with USE ROLE and USE WAREHOUSE. Let's check our context. (We ran all of this lesson's SQL with the Snowflake CLI on our trial account; it works the same pasted into Snowsight.)
-- Which role, warehouse and database am I using right now?
SELECT CURRENT_ROLE(), CURRENT_WAREHOUSE(), CURRENT_DATABASE();| CURRENT_ROLE() | CURRENT_WAREHOUSE() | CURRENT_DATABASE() |
|---|---|---|
| TEACHTRAILS_ROLE | SHOPKART_WH | None |
We have a role and a warehouse but no database yet. Let's fix that.
How Snowflake organises things
π’Organization
Your company: can own several accounts (e.g. one per region)
πAccount
One Snowflake account with its own URL
Users & roles
Who can do what
Warehouses
Compute
Resource monitors
Credit limits
ποΈDatabase: SHOPKART
A container for schemas
πSchemas: RAW, ANALYTICS
Folders inside a database
Tables & views
Your data
Stages & file formats
For loading files
Pipes, streams, tasks
Automation (lesson 7)
Functions & procedures
Your own code
So the full name of a table is database.schema.table, like shopkart.raw.orders. Warehouses, users and roles don't belong to a database: they belong to the whole account.
Create ShopKart's database and schemas
A common, simple layout: one schema for data exactly as it arrived (raw) and one for clean, report-ready tables (analytics). Bigger teams often use three layers (bronze, silver, gold); same idea.
-- A database for ShopKart, with one schema per stage of the data
CREATE OR REPLACE DATABASE shopkart;
CREATE SCHEMA shopkart.raw; -- data exactly as it arrived
CREATE SCHEMA shopkart.analytics; -- clean tables for reports
DROP SCHEMA shopkart.public; -- we don't need the default one
USE SCHEMA shopkart.raw; -- unqualified names now mean shopkart.raw.<name>SHOW SCHEMAS IN DATABASE shopkart;| name | database_name | owner | retention_time |
|---|---|---|---|
| ANALYTICS | SHOPKART | TEACHTRAILS_ROLE | 1 |
| INFORMATION_SCHEMA | SHOPKART | 1 | |
| RAW | SHOPKART | TEACHTRAILS_ROLE | 1 |
INFORMATION_SCHEMA appears in every database automatically. It's a read-only set of views describing everything inside: tables, columns, load history. We'll query it often. retention_time = 1 means one day of Time Travel (lesson 6).
Create tables
CREATE TABLE customers (
customer_id NUMBER(10,0) NOT NULL,
name VARCHAR NOT NULL,
email VARCHAR,
city VARCHAR,
signup_date DATE
);
CREATE TABLE products (
product_id NUMBER(10,0) NOT NULL,
name VARCHAR NOT NULL,
category VARCHAR NOT NULL,
price NUMBER(10,2) NOT NULL
);INSERT INTO products VALUES
(1, 'Wireless Earbuds', 'Electronics', 2499),
(2, 'Phone Case', 'Electronics', 299),
(3, 'Smartwatch', 'Electronics', 4999);
SELECT * FROM products ORDER BY product_id;| PRODUCT_ID | NAME | CATEGORY | PRICE |
|---|---|---|---|
| 1 | Wireless Earbuds | Electronics | 2499.00 |
| 2 | Phone Case | Electronics | 299.00 |
| 3 | Smartwatch | Electronics | 4999.00 |
Data types you'll actually use
| Type | Use it for | Notes |
|---|---|---|
| NUMBER(p, s) | IDs, quantities, money | INT, INTEGER, BIGINT are all NUMBER(38,0). Use NUMBER(10,2) for prices. |
| FLOAT | Scientific values | Not for money: rounding errors. |
| VARCHAR | Text | No need for a length; VARCHAR costs the same as VARCHAR(50). |
| BOOLEAN | Yes/no flags | |
| DATE | Calendar dates | |
| TIMESTAMP_NTZ | Date and time, no time zone | The default TIMESTAMP. Store UTC in it. |
| TIMESTAMP_LTZ / _TZ | Time with time zone | LTZ shows in the session's zone; TZ keeps the original offset. |
| VARIANT | JSON and other semi-structured data | Lesson 5 |
| ARRAY, OBJECT | Lists and key-value data | Lesson 5 |
Constraints: the surprise
-- Primary keys are for documentation: Snowflake does NOT enforce them
CREATE OR REPLACE TABLE pk_test (id NUMBER PRIMARY KEY, name VARCHAR NOT NULL);
INSERT INTO pk_test VALUES (1, 'Asha'), (1, 'Asha again');
SELECT * FROM pk_test;
-- ...but NOT NULL is enforced
INSERT INTO pk_test VALUES (2, NULL);| ID | NAME |
|---|---|
| 1 | Asha |
| 1 | Asha again |
100072 (22000): DML operation to table PK_TEST failed on column NAME with error:
NULL result in a non-nullable columnTable types
DROP TABLE pk_test;
CREATE TRANSIENT TABLE staging_orders (order_id NUMBER, status VARCHAR); -- no Fail-safe
CREATE TEMPORARY TABLE scratch (x NUMBER); -- gone when the session ends
SELECT table_name, table_type, is_transient, retention_time
FROM shopkart.information_schema.tables
WHERE table_schema = 'RAW'
ORDER BY table_name;| TABLE_NAME | TABLE_TYPE | IS_TRANSIENT | RETENTION_TIME |
|---|---|---|---|
| CUSTOMERS | BASE TABLE | NO | 1 |
| PRODUCTS | BASE TABLE | NO | 1 |
| SCRATCH | LOCAL TEMPORARY | None | 0 |
| STAGING_ORDERS | BASE TABLE | YES | 1 |
| Type | Time Travel | Fail-safe | Lives until | Good for |
|---|---|---|---|---|
| Permanent | 0β90 days (Enterprise; 1 day on Standard) | 7 days | You drop it | Important business data |
| Transient | 0β1 day | None | You drop it | Staging tables you can rebuild |
| Temporary | 0β1 day | None | The session ends | Scratch work |
You'll also meet external tables (read files in cloud storage without loading them), Iceberg tables (open format, stored in your cloud), hybrid tables (fast single-row reads and writes, with enforced primary keys) and dynamic tables (lesson 8).
Roles: who can do what
In Snowflake, privileges are given to roles, and roles are given to users. Every account starts with these system roles:
| Role | What it's for |
|---|---|
| ACCOUNTADMIN | Top of the tree: billing, resource monitors, account settings. Few people, used rarely, with MFA. |
| SECURITYADMIN | Manages grants; can grant any privilege. Inherits USERADMIN. |
| USERADMIN | Creates users and roles |
| SYSADMIN | Creates warehouses, databases and everything inside them. Your custom roles should roll up to it. |
| PUBLIC | Every user has it automatically. Grant almost nothing to it. |
For this course we created a custom role, TEACHTRAILS_ROLE, that may create databases and use one warehouse, and granted it to SYSADMIN so admins can still see everything it creates. Lesson 9 goes deep on roles, masking and row-level security.
π― Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1Describe the Snowflake object hierarchy.Fresher+
Q2Does Snowflake enforce primary keys?Fresher+
Q3Permanent vs transient vs temporary tables?1β3 yrs+
Q4What are the system-defined roles and how should custom roles fit in?1β3 yrs+
Q5Why might a query fail with 'object does not exist or not authorized' when the table clearly exists?3+ yrs+
Key takeaways
- βGet the context right (role, warehouse, database, schema) and Snowflake is just SQL.
- βShopKart now has a database with raw and analytics schemas.
- βSnowflake trusts you on uniqueness, so plan de-duplication.
- βPick the table type by how much you'd miss the data.
Frequently asked questions
What is Snowsight?
Snowflake's website (app.snowflake.com) where you write and run SQL and Python, load files, see query history, build dashboards and manage users. SQL files now live in Workspaces; old-style worksheets were moved there automatically.
Which role should I use day to day?
Not ACCOUNTADMIN. Use SYSADMIN (or a custom role made for your team) to create databases and tables, and keep ACCOUNTADMIN for account-level jobs like billing and resource monitors. It's the most common security mistake in new accounts.
Why does Snowflake ignore my PRIMARY KEY?
Snowflake stores PRIMARY KEY, UNIQUE and FOREIGN KEY constraints but doesn't enforce them on normal tables, for speed at scale. Only NOT NULL is enforced. Your pipeline must prevent duplicates itself (for example with MERGE or QUALIFY ROW_NUMBER() = 1).
Permanent, transient or temporary: which table should I use?
Permanent for important data. Transient for data you can rebuild (staging tables), because it has no Fail-safe and costs less storage. Temporary for scratch work inside one session; it disappears when the session ends.
Are Snowflake names case-sensitive?
Not unless you put them in double quotes. shopkart, Shopkart and SHOPKART are the same object (stored as SHOPKART). "Shopkart" in quotes is a different, case-sensitive name, which causes endless confusion, so avoid quotes.
π§ Quick check: getting started
1. Which is the correct order, biggest to smallest?
2. Which constraint does Snowflake enforce on normal tables?
3. A staging table you rebuild every night should be...
4. What do you need to run any query?
Checking your accessβ¦