Creating Tables in Snowflake: Types, Examples & Best Practices
Learn how to create different types of tables in Snowflake, including permanent, temporary, external, and dynamic tables. Includes step-by-step examples and best practices.
Snowflake is a powerful cloud-based data warehousing platform that helps organizations store, manage, and analyze their data efficiently. Unlike traditional data warehouses that require complex hardware setups, Snowflake runs entirely in the cloud, making it easier for businesses to scale their data operations as needed.
Creating tables in Snowflake is a fundamental skill that forms the foundation of data management. Tables are where you store your structured data, making it possible to run queries, generate reports, and derive valuable insights from your information. Whether you’re working with customer data, sales figures, or analytical results, understanding how to create and manage tables in Snowflake is essential.
In this tutorial, you’ll learn everything you need to know about creating tables in Snowflake. We’ll cover the different types of tables, show you step-by-step examples, and share best practices for table design. By the end, you’ll be confident in choosing the right table type for your needs and creating tables that follow industry standards for performance and maintainability.
Understanding Table Types in Snowflake
Before we dive into code examples on how to create tables, let’s explore different table types in Snowflake as they each serve unique purposes and have distinct characteristics in terms of data persistence, accessibility, and storage location.
Permanent tables
Permanent tables are the standard table type in Snowflake. They persist until explicitly dropped and are stored within Snowflake’s internal storage. These tables are ideal for storing your core business data that needs to be retained long-term and accessed across multiple sessions. The data in permanent tables remains intact between sessions and can be accessed by any authorized user.
Temporary tables
Temporary tables are session-specific tables that automatically drop when your current session ends. They serve as workspace tables for intermediate processing steps, helping organize complex data transformations without cluttering your permanent storage. The data in temporary tables is only visible to the session that created them and automatically cleans up when the session closes.
External tables
External tables provide a way to query data that resides outside of Snowflake’s storage. They act as a metadata layer that maps to data in external storage locations like AWS S3 or Azure Blob Storage. Rather than ingesting the data, external tables create a reference to it, allowing you to query external data directly. This approach is particularly valuable when working with data that needs to remain in its source location or requires frequent updates from external systems.
Dynamic tables
Dynamic tables are a powerful feature in Snowflake that automatically maintain up-to-date results of a query. They act as materialized views that refresh automatically based on changes in the underlying source tables. When you create a dynamic table, you define it using a SELECT statement, and Snowflake automatically manages the refresh process to ensure the data stays current.
Dynamic tables are particularly useful for:
Building real-time dashboards that need fresh data without manual refreshes
Maintaining aggregated or transformed versions of source data that update automatically
Creating dependent data models where downstream tables need to reflect upstream changes
Optimizing query performance by pre-computing complex transformations
Key features of dynamic tables include:
Configurable refresh intervals (from 1 minute to 24 hours)
Automatic dependency tracking of source tables
Target lag time settings to control data freshness
Incremental processing to minimize compute costs
Built-in monitoring and optimization capabilities
Each table type has its distinct purpose in data architecture. Permanent tables form the foundation of your data warehouse, temporary tables facilitate data processing workflows, external tables enable integration with external data sources, and dynamic tables provide automated, real-time data transformations.
Comparing Snowflake tables
In the table below, we’ve outlined the different types of Snowflake tables in a concise, quick-reference guide:
Table Type
Persistence
Visibility
Best For
Permanent
Until dropped
Any session
Core business data
Temporary
Session-only
Same session
Intermediate transformations
External
External storage
Any session
Querying external data (e.g., S3)
Dynamic
Auto-refreshing
Any session
Real-time analytics
Create Tables: Setting Up Snowflake
Before running the examples in this tutorial, you’ll need access to a Snowflake environment. Here are several ways to connect to and run Snowflake commands:
1. Snowflake web interface (Snowsight)
The simplest way to get started is through Snowflake’s web interface:
The first statement defines a file format specification that tells Snowflake how to parse external CSV files, including the delimiter, header handling, and NULL value representations.
The second statement creates a stage object that establishes a connection to external cloud storage (in this case, S3) using the provided credentials. This stage acts as a reference point for accessing the external data files.
The third statement creates the external table itself, using column definitions with AS clauses to explicitly cast the raw string data from the CSV into proper Snowflake data types. The WITH LOCATION clause points to the specific path within the stage where the files reside.
The PATTERN parameter filters which files should be included using regex matching, ensuring only CSV files are processed.
Prerequisites to run this external table creation query:
1. Access to a Snowflake account with permissions to:
Create file formats
Create stages
Create external tables
2. Valid AWS credentials (AWS_KEY_ID and AWS_SECRET_KEY) with permissions to:
Read from the S3 bucket
List objects in the bucket
3. Source data requirements:
CSV files stored in an S3 bucket
Files follow a consistent format with four columns
Column data matches specified types:
customer_id as string
purchase_date as date
product_id as string
amount as decimal
4. Network connectivity:
Network access to AWS S3
Proper security group and firewall settings
5. Compute resources:
Active warehouse with adequate computing capacity
Sufficient user credits/quota
Example 4: Creating a dynamic table
This example creates a dynamic table that maintains an up-to-date summary of sales data:
-- Create a dynamic table for real-time sales analyticsCREATEORREPLACE DYNAMIC TABLE daily_sales_summary
TARGET_LAG ='20 minutes'
WAREHOUSE ='COMPUTE_WH'ASSELECT
DATE_TRUNC('day', sale_timestamp)as sale_date,
product_category,SUM(sale_amount)as total_sales,COUNT(DISTINCT customer_id)as unique_customers
FROM sales_transactions
GROUPBY1,2;
The TARGET_LAG parameter of '20 minutes' defines the maximum allowed delay between updates to the source table and when those changes are reflected in the dynamic table. This ensures data freshness within that time window.
The WAREHOUSE parameter specifies which compute resources (in this case COMPUTE_WH) will be used to periodically refresh the dynamic table. This warehouse must have adequate capacity to handle the refresh operations.
The dynamic table automatically updates its contents when the underlying sales_transactions table changes without requiring manual intervention. This provides near real-time analytics capabilities.
By maintaining pre-aggregated daily sales summaries grouped by product category, the dynamic table enables faster querying compared to calculating these metrics on demand from the raw transaction data. This improves query performance for reporting and analytics use cases.
Each of these examples demonstrates different table creation scenarios you might encounter in real-world applications. Remember to adjust column names, data types, and other parameters according to your specific needs.
Best Practices for Creating Tables in Snowflake
Let's explore some best practices to follow when creating tables in Snowflake to ensure maintainability, performance, and data quality.
1. Naming conventions
Always use clear, consistent names for your tables and columns:
-- Good naming examplesCREATETABLE customer_orders (
order_id INTEGER,
customer_email VARCHAR,
order_date DATE);-- Bad naming examplesCREATETABLE Orders123 (
ID INTEGER,
email VARCHAR,
dt DATE);
Use lowercase letters and underscores (snake_case)
Avoid spaces and special characters
Make names descriptive but not too long
Use singular form for table names (customer not customers)
Add prefixes for different environments (dev_, test_, prod_)
2. Column data types
Choose the right data type to save storage and improve performance:
-- Good data type choicesCREATETABLE products (
product_id INTEGER,
price DECIMAL(10,2),-- For money values
name VARCHAR(100),-- Set a reasonable limit
description TEXT,-- For very long text
is_active BOOLEAN-- Instead of VARCHAR or INTEGER);
Don’t cluster by columns with too many unique values
4. Adding table constraints
Use constraints to keep your data clean:
CREATETABLE users (
user_id INTEGERPRIMARYKEY,-- Ensures unique IDs
email VARCHAR(255)UNIQUE,-- No duplicate emails
username VARCHAR(50)NOTNULL,-- Must have a value
age INTEGERCHECK(age >=18)-- Must be 18 or older);
-- Bad practice: No primary keyCREATETABLE orders (dateVARCHAR,-- Wrong data type for dates
amount VARCHAR(10),-- Wrong data type for numbersstatustext-- Inconsistent case with other columns);Работает на
Do this instead:
-- Good practiceCREATETABLE orders (
order_id INTEGERPRIMARYKEY,
order_date DATE,
amount DECIMAL(10,2),statusVARCHAR(20));Работает на
The improved version ensures data integrity with a primary key, uses correct data types for dates and numbers to enable efficient filtering and calculations, and maintains consistency in column definitions for better readability and compatibility.
6. Performance tips
Optimizing table performance in Snowflake can significantly improve query speed and reduce storage costs. Follow these best practices to ensure your tables are efficient and scalable.
Create smaller tables instead of one huge table
Add column descriptions using COMMENT
Set up automatic data cleanup rules
Test your table design with real data
Monitor table usage and adjust as needed
7. Security best practices
Proper security measures are essential to protect sensitive data and control access. Implement these best practices to safeguard your Snowflake environment from unauthorized access and data breaches.
Always set proper access permissions
Use row-level security when needed
Encrypt sensitive columns
Keep track of who can access what
Regularly review access patterns
Remember: A well-designed table makes your work easier later on. Take time to plan your table structure before creating it!
Conclusion
In this tutorial, we’ve covered the essentials of creating tables in Snowflake, including:
Different types of tables (permanent, temporary, external, and dynamic)
Step-by-step examples for creating each type
Best practices for table design and management
Common pitfalls to avoid
This knowledge forms the foundation for building efficient and scalable data solutions in Snowflake.
Next Steps
To deepen your Snowflake expertise, check out these valuable resources:
Don’t forget, the best way to learn is by doing. Start creating tables, experiment with different types, and build real projects. As you encounter challenges, refer back to these resources and keep exploring new features of Snowflake.
Snowflake Create Table FAQs
What are the different types of tables in Snowflake?⌄
Snowflake supports four main table types: permanent tables for long-term data storage, temporary tables for session-specific use, external tables for querying external data sources, and dynamic tables for automatic query result maintenance.
How do I create a basic table in Snowflake?⌄
Use the CREATE TABLE command with your desired schema. For example: "CREATE TABLE customers (customer_id INTEGER PRIMARY KEY, first_name VARCHAR(50), last_name VARCHAR(50))". Include appropriate data types and constraints.
What is a dynamic table in Snowflake and when should I use it?⌄
Dynamic tables automatically maintain up-to-date results of a query, similar to materialized views. They're ideal for real-time dashboards, automated data transformations, and maintaining aggregated data that needs frequent updates.
What are the best practices for naming tables in Snowflake?⌄
Use lowercase letters with underscores (snake_case), avoid spaces and special characters, make names descriptive but concise, use singular form for table names, and consider adding environment prefixes (dev_, test_, prod_).
How can I improve table performance in Snowflake?⌄
Improve performance by using appropriate clustering keys, choosing correct data types, setting proper constraints, creating smaller focused tables instead of large ones, and regularly monitoring table usage patterns.
Bex Tuychiev builds voice agents and LLM systems, and most of his work goes into making them reliable enough to run in production, preferably in healthcare.
This guide breaks down star and snowflake schemas — two common ways to organize data in warehouses. You’ll learn how they work, how they’re different, and when to use each to fit your data needs.
Learn how to efficiently insert data into Snowflake tables using the INSERT INTO statement. This guide covers syntax, use cases, best practices, and troubleshooting techniques.
Learn the fundamentals of cloud data warehouse management using Snowflake. Snowflake is a cloud-based platform that offers significant benefits for companies wanting to extract as much insight from their data as quickly and efficiently as possible.
Discover how to create tables in Databricks using the CREATE TABLE command. Learn different methods for different scenarios, including how to a create a table from existing data and how to CREATE TABLE as SELECT.
Understand how CREATE TABLE shapes your database. Learn the key syntax, data types, constraints, and optimization techniques for building scalable schemas.
Snowflake is a powerful cloud-based data warehousing platform that helps organizations store, manage, and analyze their data efficiently. Unlike traditional data warehouses that require complex hardware setups, Snowflake runs entirely in the cloud, making it easier for businesses to scale their data operations as needed.
Creating tables in Snowflake is a fundamental skill that forms the foundation of data management. Tables are where you store your structured data, making it possible to run queries, generate reports, and derive valuable insights from your information. Whether you’re working with customer data, sales figures, or analytical results, understanding how to create and manage tables in Snowflake is essential.
In this tutorial, you’ll learn everything you need to know about creating tables in Snowflake. We’ll cover the different types of tables, show you step-by-step examples, and share best practices for table design. By the end, you’ll be confident in choosing the right table type for your needs and creating tables that follow industry standards for performance and maintainability.
Understanding Table Types in Snowflake
Before we dive into code examples on how to create tables, let’s explore different table types in Snowflake as they each serve unique purposes and have distinct characteristics in terms of data persistence, accessibility, and storage location.
Permanent tables
Permanent tables are the standard table type in Snowflake. They persist until explicitly dropped and are stored within Snowflake’s internal storage. These tables are ideal for storing your core business data that needs to be retained long-term and accessed across multiple sessions. The data in permanent tables remains intact between sessions and can be accessed by any authorized user.
Temporary tables
Temporary tables are session-specific tables that automatically drop when your current session ends. They serve as workspace tables for intermediate processing steps, helping organize complex data transformations without cluttering your permanent storage. The data in temporary tables is only visible to the session that created them and automatically cleans up when the session closes.
External tables
External tables provide a way to query data that resides outside of Snowflake’s storage. They act as a metadata layer that maps to data in external storage locations like AWS S3 or Azure Blob Storage. Rather than ingesting the data, external tables create a reference to it, allowing you to query external data directly. This approach is particularly valuable when working with data that needs to remain in its source location or requires frequent updates from external systems.
Dynamic tables
Dynamic tables are a powerful feature in Snowflake that automatically maintain up-to-date results of a query. They act as materialized views that refresh automatically based on changes in the underlying source tables. When you create a dynamic table, you define it using a SELECT statement, and Snowflake automatically manages the refresh process to ensure the data stays current.
Dynamic tables are particularly useful for:
Key features of dynamic tables include:
Each table type has its distinct purpose in data architecture. Permanent tables form the foundation of your data warehouse, temporary tables facilitate data processing workflows, external tables enable integration with external data sources, and dynamic tables provide automated, real-time data transformations.
Comparing Snowflake tables
In the table below, we’ve outlined the different types of Snowflake tables in a concise, quick-reference guide:
Table Type
Persistence
Visibility
Best For
Permanent
Until dropped
Any session
Core business data
Temporary
Session-only
Same session
Intermediate transformations
External
External storage
Any session
Querying external data (e.g., S3)
Dynamic
Auto-refreshing
Any session
Real-time analytics
Create Tables: Setting Up Snowflake
Before running the examples in this tutorial, you’ll need access to a Snowflake environment. Here are several ways to connect to and run Snowflake commands:
1. Snowflake web interface (Snowsight)
The simplest way to get started is through Snowflake’s web interface:
2. Snowflake CLI (command-line tool)
For command-line access:
You can find your Snowflake account credentials in the following places:
For security, never share or commit these credentials. Store them securely in environment variables or a configuration file.
3. Python connection
If you’re using Python, you can use the
snowflake-connector-pythonlibrary:Important Security Note:
Now that our setup is ready, let’s create tables!
Creating Tables in Snowflake: Step-by-Step Examples
Example 1: Creating a simple Snowflake table
Let’s create a table to store customer information. This example demonstrates basic table creation with different data types and constraints.
Key points about this example:
CREATE OR REPLACE TABLE- Creates a new table or replaces it if it already existsPRIMARY KEY- Ensures unique identification of each recordNOT NULL- Prevents null values in required fieldsUNIQUE- Ensures email addresses are not duplicatedTIMESTAMP_NTZ- Timestamp without time zoneDEFAULT- Automatically sets creation timestampExample 2: Creating a temporary table
Temporary tables are perfect for intermediate data processing. Here’s an example that creates a temporary table for analyzing customer orders:
Key points about temporary tables:
TEMPORARYkeyword indicates that this table will only exist within the current session. This means other users cannot see or access this table.CREATE TABLE AS(CTAS) allows you to create and populate a table in a single step by combining the table definition with a SELECT statement.Example 3: Creating an external table in Snowflake
This example shows how to create an external table that reads data from files stored in a cloud storage bucket:
The first statement defines a file format specification that tells Snowflake how to parse external CSV files, including the delimiter, header handling, and NULL value representations.
The second statement creates a stage object that establishes a connection to external cloud storage (in this case, S3) using the provided credentials. This stage acts as a reference point for accessing the external data files.
The third statement creates the external table itself, using column definitions with AS clauses to explicitly cast the raw string data from the CSV into proper Snowflake data types. The WITH LOCATION clause points to the specific path within the stage where the files reside.
The PATTERN parameter filters which files should be included using regex matching, ensuring only CSV files are processed.
Prerequisites to run this external table creation query:
1. Access to a Snowflake account with permissions to:
2. Valid AWS credentials (
AWS_KEY_IDandAWS_SECRET_KEY) with permissions to:3. Source data requirements:
customer_idas stringpurchase_dateas dateproduct_idas stringamountas decimal4. Network connectivity:
5. Compute resources:
Example 4: Creating a dynamic table
This example creates a dynamic table that maintains an up-to-date summary of sales data:
The
TARGET_LAGparameter of '20 minutes' defines the maximum allowed delay between updates to the source table and when those changes are reflected in the dynamic table. This ensures data freshness within that time window.The
WAREHOUSEparameter specifies which compute resources (in this caseCOMPUTE_WH) will be used to periodically refresh the dynamic table. This warehouse must have adequate capacity to handle the refresh operations.The dynamic table automatically updates its contents when the underlying
sales_transactionstable changes without requiring manual intervention. This provides near real-time analytics capabilities.By maintaining pre-aggregated daily sales summaries grouped by product category, the dynamic table enables faster querying compared to calculating these metrics on demand from the raw transaction data. This improves query performance for reporting and analytics use cases.
Each of these examples demonstrates different table creation scenarios you might encounter in real-world applications. Remember to adjust column names, data types, and other parameters according to your specific needs.
Best Practices for Creating Tables in Snowflake
Let's explore some best practices to follow when creating tables in Snowflake to ensure maintainability, performance, and data quality.
1. Naming conventions
Always use clear, consistent names for your tables and columns:
Tips for naming:
dev_,test_,prod_)2. Column data types
Choose the right data type to save storage and improve performance:
Common data types to use:
NUMBER/INTEGER: For whole numbersDECIMAL/NUMERIC: For precise decimal numbers (especially money)VARCHAR: For text with a known maximum lengthTEXT: For unlimited length textTIMESTAMP_NTZ: For dates and times (no timezone)BOOLEAN: For true/false values3. Using clustering keys
Add clustering keys to improve query performance:
When to use clustering:
4. Adding table constraints
Use constraints to keep your data clean:
Important constraints:
PRIMARY KEY: For unique identifiersFOREIGN KEY: For linking tables togetherNOT NULL: For required fieldsUNIQUE: For fields that can’t have duplicatesCHECK: For simple data validation5. Common mistakes to avoid
Don’t do this:
Do this instead:
The improved version ensures data integrity with a primary key, uses correct data types for dates and numbers to enable efficient filtering and calculations, and maintains consistency in column definitions for better readability and compatibility.
6. Performance tips
Optimizing table performance in Snowflake can significantly improve query speed and reduce storage costs. Follow these best practices to ensure your tables are efficient and scalable.
7. Security best practices
Proper security measures are essential to protect sensitive data and control access. Implement these best practices to safeguard your Snowflake environment from unauthorized access and data breaches.
Remember: A well-designed table makes your work easier later on. Take time to plan your table structure before creating it!
Conclusion
In this tutorial, we’ve covered the essentials of creating tables in Snowflake, including:
This knowledge forms the foundation for building efficient and scalable data solutions in Snowflake.
Next Steps
To deepen your Snowflake expertise, check out these valuable resources:
1. Interactive courses:
2. Comprehensive tutorials:
3. Career resources:
Don’t forget, the best way to learn is by doing. Start creating tables, experiment with different types, and build real projects. As you encounter challenges, refer back to these resources and keep exploring new features of Snowflake.