Snowflake 简明教程

Snowflake - Table & View Types

Table Types

Snowflake 根据表的使用方式和性质将其分类为不同类型。有四种类型的表 −

Snowflake categorizes tables into different types based on its uses and nature. There are four types of tables −

Permanent Table

  1. Permanent tables are created in the database.

  2. These tables persist until deleted or dropped from database.

  3. These tables are designed to store the data that requires highest level of data protection and recovery.

  4. These are default table type.

  5. Time travel is possible in these tables up to 90 days, i.e., that someone can get the data up to 90 days back.

  6. It is Fail-safe and data can be recovered if lost due to fail.

Temporary Table

  1. Temporary tables, as the name indicates, exist for a shorter duration.

  2. These tables persist for a session.

  3. If a user wants a temporary table for his subsequent queries and analytics, then once a session is completed, it automatically drops the temporary table.

  4. It is mostly used for transitory data like ETL/ELT

  5. Time travel is possible in temporary tables but only 0 to 1 day.

  6. It is not fail-safe, which means data cannot be recovered automatically.

Transient Table

  1. These tables persist until the users drop or delete them.

  2. Multiple users can access a transient table.

  3. It is used where "data persistence" is required but doesn’t need "data retention" for a longer period. For example, the details of guest visitors of a website, the details of users who visited a website as well as registered on it, so after registration, storing the details in two different tables might not be required.

  4. Time travel is possible in transient tables but only for 0 to 1 day.

  5. It is also not failed safe.

External Table

  1. These tables persist until removed.

  2. Here, the word removed is used, as external tables are like outside of snowflake and they can’t be dropped or deleted. It should be removed.

  3. It can be visualized as Snowflake over an external data lake, i.e., the main source of data lake is pointed to Snowflake to utilize the data as per user’s need.

  4. Data cannot be directly accessed. It can be accessed in Snowflake via an external stage.

  5. External tables are only meant for reading.

  6. Time travel is not possible for external tables.

  7. It is not fail-safe inside Snowflake environment.

View Types

Snowflake 中有三个主要分类的视图:

There are three main categorized views in Snowflake −

Standard View

  1. It is the default view type.

  2. Select queries for tables to view data.

  3. User can execute queries based on role and permissions.

  4. Underlying DDL is available to any role who has access to these view.

Secure View

  1. Secure View means it can be accessed only by authorized users.

  2. Authorized users can view the definition and details.

  3. Authorized users with proper role can access these tables and execute the queries.

  4. In secure view, Snowflake query optimizer bypasses optimizations used for regular view.

Materialized View

  1. Materialized view is more like a table.

  2. These views store the result from the main source using filter conditions. For example, a company has records of all employees who are active, inactive, or deceased from starting of the company. Now, if a user needs the details of active employees only, then the main table can be queried and stored as materialized view for further analytics.

  3. Materialized view is auto-refreshed, i.e., whenever the main table gets additional/new employee records, it refreshes the materialized view as well.

  4. Snowflake supports secure materialized view as well.

  5. Materialized views are maintained automatically, and it can consume significant compute resources.

  6. Total costs for materialized views are based on "data storage + compute + serverless services."

  7. Compute charges per materialized view are calculated based on the volume of data changes.