Snowflake - Container Hierarchy
User -> Account -> Database -> Schema -> Table
Guidance Questions
-
How does [Database] -> [Schema] -> [Table] fit with [Account]?
- [User] -> [Account] -> [Database] -> [Schema] -> [Table]
- Accounts belong to a single user, databases belong to a single account, schemas belong to a single database, tables belong to a single database.
- Source
-
What are the four types of Snowflake tables and which ones have fail-safe storage?
- Types of tables:
- Permanent Table.
- The default type of table when creating tables.
- Visible to all users with appropriate permissions.
- All data is stored in permanent tables.
- 7-day Fail safe retention period.
- Temporary Table.
- Lasts single session.
- Only visible to the user in the session.
- Data not recoverable once session ends.
- Contribute towards storage bill while existing.
- No fail safe storage.
- Used for storing transitory data, like ETL state, etc.
- Transient Table.
- Like permanent tables, without fail safe.
- Cheaper that permanent tables, due to no fail safe storage.
- Need to be explicitly dropped.
- External Table
- Stored externally, but read as if stored in Snowflake.
- Let's you store file metadata in Snowflake, like:
- Filenames.
- Version identifiers.
- Row and Column numbers.
- Can access any data stored in a format accessible by COPY INTO
<table>
. - Read Only, you can't use DML on these tables.
- Can use them for DDL, like SELECT and JOIN, queries are slower than with internal tables.
- Can create Views against external tables, materialized views remove query speed penalty.
- No fail safe storage.
- Source for external tables.
- Source for internal tables.
- Permanent Table.
- Types of tables:
-
What are the differences between standard and secure views?
0. View definition - A View is a subset of a database generated by a query which has been named and stored as a persistent database object.
1. Views are created using theCREATE VIEW
statement.
2. Views can be queried, joined like database tables.
3. Non-secure views are visible to all users with database access.- There are 3 types of views:
- Standard Views:
- Non-Materialized - They are not stored as permanent objects, only as queries.
- Secure Views:
- Can be materialized or not.
- Only query is only visible to authorized users.
- Security focused optimizer, not as efficient a regular view.
- Source
- Materialized Views:
- Materialized: When created they turn the query result into a separate persistent data object.
- Function like data marts, AKA they are specific subsets of datasets, which makes them more efficient for querying.
- Incur storage costs just like a table.
- Have additional restrictions.
- Source
- Standard Views:
- There are 3 types of views:
-
What are the different types of stages?
- External stages, hosted outside of Snowflake in buckets like:
- Amazon S3
- Google Cloud Storage
- Microsoft Azure
- Internal Stages, hosted inside of Snowflake:
- Table Stage:
- Automatically created for each table.
- Not visible in webUI.
- Stores files owned by one or more users but loaded into a single table.
- Not a separate database object.
- Only the table owner can interact with the staged files.
- User Stage:
- Automatically created for each user.
- Not visible in webUI.
- Cannot be altered or dropped.
- Stores files managed by single user.
- Named Stage:
- A database object created in a schema.
- Can store files owned by many users and loaded into many tables.
- CRUD access controlled by security access control privileges.
- Are created using the
CREATE STAGE
command. - Definable via webUI.
- Viewable in WebUI by users.
- Can be internal or external.
- Named stages can be hosted on any and all of the supported platform at the same time.
- Source
- Table Stage:
- Source
- External stages, hosted outside of Snowflake in buckets like:
-
What are the command-line commands that moves filed into stages? What command moves files from stages into tables? From tables back out of stages?
- Put can be use by SnowSQL and Snowflake CLI to move files into Stages.
- COPY INTO
<table>
moves files from stages into tables.- Data stored in archival storage can't be loaded this way.
- Source
- COPY INTO
<location>
unloads files from tables and puts them into any kind of stage.- Can be downloaded into internal stages using the
GET
command. - Source
- Can be downloaded into internal stages using the
-
Disregarding replication functionality, can a database span multiple accounts? Can a schema span multiple accounts? Can an account span multiple cloud-as-a-platform providers?
- No. A database cannon span multiple accounts.
- No. A schema can't span multiple accounts.
- No. An account cannot span multiple Cloud providers(AWS,Azure,GCP).
- Source
-
Can a single Snowflake account load data from stages on more than one cloud provider?
- Yes with external stages. See the answer to #5.
-
Can you deduce the cloud platform provider and region of an account based on the account URL?
- If it's name is {name}.snowflakecomputing.com it's AWS us-west-2. Otherwise the format is {account}.{region}.{provider}.snowflakecomputing.com
- Source
-
What is a namespace in Snowflake and how does it relate to the container hierarchy?
- Database.Schema = Namespace
- The namespace is like a folder for tables, making it easier to group similar tables together.
- The namespace is inferred from the current database and schema used in the session.
- Source
Quiz:
- Which of these are Snowflake table types?
- Permanent.
- External.
- Temporary.
- Transient.
- Which of the following are Snowflake view types?
- Secure.
- Standard.
- Materialised.
- What are the three Snowflake Stage types?
- User.
- Table.
- Named.
- Named stages come in two varieties, what are they?
- Internal.
- External.
- What type of view is most like a table?
- Materialised.
- Which type of view has na extra layer of protection to hide the SQL code from unauthorised viewing?
- Secure.
- In a Snowflake account named MX43210, you need to set a user's default namespace to a database called MYDB and the PUBLIC schema. Which of the following commands would you use?
- set default_namespace = mydb.public.
- Which statements are true about the Snowflake container hierarchy? Select all that apply.
- Accounts contain databases which contain schemas.
- Schemas contain tables as well as views.
- In the Snowflake container hierarchy, what container is represented as a URL (for example: https://HJ54364.snowflakecomputing.com)
- Account
- Fail-Safe is a seven-day history of data and is automatically available on which table types?
- Permanent.
- Each Snowflake account comes with two shared databases. One is a set of sample data and the other contains Account Usage information. Check all true statements about these shared databases.
- SNOWFLAKE contains a scheme called ACCOUNT_USAGE.
- SNOWFLAKE_SAMPLE_DATA contains several schemas from TPC(tpc.org)
- ACCOUNT_USAGE is a schema filled with secure views.
- Which of the following statements are true about the Fail-safe?
- Only a Snowflake employee can recover data from Fail-safe storage.
- The data stored as part of Fail-safe is part of storage costs charged to customers.
- Time travel is available for which table types?
- Permanent.
- Temporary.
- Transient.
- Which types of stages are automatically available in snowflake and do not need to be created or configured?
- User.
- Table.
- Which table type disappears after the close of the session and therefore has no Fail-safe and no Time Travel options after the close of the session?
- Temporary.
- You set up a Snowflake account, choosing AWS as your cloud platform provider. What stages can you use to load data files?
- USER
- TABLE
- NAMED INTERNAL
- NAMED EXTERNAL - using S3 Buckets
- NAMED EXTERNAL - using Azure BLOB Storage
- NAMED EXTERNAL - using GCS/GCP Buckets
- Which of the following object types are stored within schemas?
- Stages.
- File Formats
- Sequences
- Stored Procedures
- User Defined Functions