Snowflake Table Types

Snowflake provides various table types to meet different data storage and processing requirements. Each table type has specific characteristics regarding persistence, performance, cost, and Time Travel capabilities.

Overview of Table Types

┌───────────────────────────────────────────────────────────────────────┐
│                         SNOWFLAKE TABLE TYPES                         │
├───────────────────────────────────────────────────────────────────────┤
│                                                                       │
│  ┌──────────────────┐  ┌───────────────────┐  ┌───────────────────┐   │
│  │    PERMANENT     │  │    TEMPORARY      │  │    TRANSIENT      │   │
│  │     TABLES       │  │     TABLES        │  │     TABLES        │   │
│  │                  │  │                   │  │                   │   │
│  │   ✓ Fail-safe    │  │   ✗ Fail-safe     │  │   ✗ Fail-safe     │   │
│  │   ✓ Time Travel  │  │   ✓ Time Travel   │  │   ✓ Time Travel   │   │
│  │     (90 days)    │  │      (1 day)      │  │     (1 day)       │   │
│  │                  │  |  Current Session  │  │  Between Sessions │   │
│  └──────────────────┘  └───────────────────┘  └───────────────────┘   │
│                                                                       │
│  ┌──────────────────┐  ┌───────────────────┐  ┌───────────────────┐   │
│  │     EXTERNAL     │  │     DYNAMIC       │  │      HYBRID       │   │
│  │     TABLES       │  │     TABLES        │  │      TABLES       │   │
│  │                  │  │                   │  │                   │   │
│  │   Data Outside   │  │   Auto-refresh    │  │    OLTP + OLAP    │   │
│  │    Snowflake     │  │   Materialized    │  │    Unistore       │   │
│  └──────────────────┘  └───────────────────┘  └───────────────────┘   │
│                                                                       │
│  ┌──────────────────┐  ┌───────────────────┐  ┌───────────────────┐   │
│  │     ICEBERG      │  │      EVENT        │  │    DIRECTORY      │   │
│  │     TABLES       │  │      TABLES       │  │     TABLES        │   │
│  │                  │  │                   │  │                   │   │
│  │   Apache Format  │  │   Log/Telemetry   │  │   Stage Files     │   │
│  │    Open Table    │  │     Storage       │  │     Catalog       │   │
│  └──────────────────┘  └───────────────────┘  └───────────────────┘   │
└───────────────────────────────────────────────────────────────────────┘

1. Permanent Tables

Permanent tables are the default table type in Snowflake, designed for storing critical business data that requires maximum data protection.

Characteristics:

Use Cases:

Creation Syntax:

CREATE TABLE customer_data (
    customer_id INTEGER,
    customer_name VARCHAR,
    created_date DATE
);

2. Temporary Tables

Temporary tables exist only within a session and are automatically dropped when the session ends.

Characteristics:

Use Cases:

Creation Syntax:

CREATE TEMPORARY TABLE temp_staging (
    id INTEGER,
    data VARCHAR
);

3. Transient Tables

Transient tables are a middle ground between permanent and temporary tables, offering persistence without Fail-safe protection.

Characteristics:

Use Cases:

Creation Syntax:

CREATE TRANSIENT TABLE staging_data (
    record_id INTEGER,
    processed_flag BOOLEAN
);

4. External Tables

External tables allow querying data stored outside of Snowflake, in external cloud storage locations.

Characteristics:

Use Cases:

Creation Syntax:

CREATE EXTERNAL TABLE ext_customer_data
WITH LOCATION = @my_external_stage/data/
FILE_FORMAT = (TYPE = PARQUET);

5. Dynamic Tables

Dynamic tables are continuously updated materialized views that automatically refresh as underlying data changes.

Characteristics:

Use Cases:

Creation Syntax:

CREATE DYNAMIC TABLE sales_summary
TARGET_LAG = '1 minute'
WAREHOUSE = compute_wh
AS
SELECT 
    product_id,
    SUM(quantity) as total_quantity,
    SUM(amount) as total_amount
FROM sales_transactions
GROUP BY product_id;

6. Hybrid Tables

Hybrid tables (Unistore) combine OLTP and OLAP capabilities, supporting both transactional and analytical workloads.

Characteristics:

Use Cases:

Creation Syntax:

CREATE HYBRID TABLE orders (
    order_id NUMBER(38,0) NOT NULL PRIMARY KEY,
    customer_id NUMBER(38,0),
    order_date TIMESTAMP_NTZ,
    status VARCHAR(20),
    INDEX idx_customer (customer_id),
    INDEX idx_date (order_date)
);

7. Iceberg Tables

Iceberg tables use Apache Iceberg table format, providing an open table format for large analytic datasets.

Characteristics:

Use Cases:

Creation Syntax:

CREATE ICEBERG TABLE customer_iceberg (
    customer_id INTEGER,
    customer_name STRING,
    registration_date DATE
)
CATALOG = 'SNOWFLAKE'
EXTERNAL_VOLUME = 'my_external_volume'
BASE_LOCATION = 'customer_data/';

8. Event Tables

Event tables are specialized tables for storing and analyzing log and telemetry data efficiently.

Characteristics:

Use Cases:

9. Directory Tables

Directory tables provide a catalog view of files in a stage, allowing SQL queries over file metadata.

Characteristics:

Use Cases:

Table Type Comparison Matrix

┌──────────────┬────────────┬─────────────┬───────────┬───────────┬───────────┐
│ Feature      │  Permanent │  Temporary  │ Transient │ External  │  Dynamic  │
├──────────────┼────────────┼─────────────┼───────────┼───────────┼───────────┤
│ Time Travel  │  0-90 days │   0-1 day   │  0-1 day  │    No     │    Yes    │
├──────────────┼────────────┼─────────────┼───────────┼───────────┼───────────┤
│ Fail-safe    │    7 days  │     No      │    No     │    No     │    No     │
├──────────────┼────────────┼─────────────┼───────────┼───────────┼───────────┤
│ Persistence  │   Until    │   Session   │   Until   │  External │   Until   │
│              │  dropped   │     only    │  dropped  │   files   │  dropped  │
├──────────────┼────────────┼─────────────┼───────────┼───────────┼───────────┤
│ DML Support  │    Yes     │     Yes     │    Yes    │    No     │    No*    │
├──────────────┼────────────┼─────────────┼───────────┼───────────┼───────────┤
│ Clone        │    Yes     │      No     │    Yes    │    No     │    Yes    │
├──────────────┼────────────┼─────────────┼───────────┼───────────┼───────────┤
│ Storage Cost │    High    │     Low     │  Medium   │   Low     │   Medium  │
├──────────────┼────────────┼─────────────┼───────────┼───────────┼───────────┤
│ Use Case     │ Production │     ETL     │  Staging  │ Data Lake │ Analytics │
└──────────────┴────────────┴─────────────┴───────────┴───────────┴───────────┘
* Dynamic tables are read-only from user perspective, auto-updated by system

Best Practices for Table Selection

  1. Use Permanent Tables for: