Getting your Trinity Audio player ready...
|
Data storage, processing, and analytic solutions have become vital for modern large-scale companies. Every fast-growing company is struggling to analyze the massive amount of data scattered at different data sources. Advanced Software as Service (SaaS) data platforms like Snowflake help you store, process, and analyze massive amounts of data. If you are considering Snowflake as your solution and are having problems creating databases and tables in Snowflake, this article will help you understand how to create tables in Snowflake.
Table of Contents
Before jumping into table creation in snowflake, basic knowledge about SQL databases and SQL tables is required. A database is a collection of tables that store a particular set of structured data. The table comprises rows and columns. Rows in a table are also known as records or tuples. Columns in the table can also be referred to as attributes.
Besides the basics of SQL database and table, you need a snowflake account as well.
If you don’t have a snowflake account, you can click here to create one.
Snowflake is a data warehouse that provides data platforms as Cloud Services. It offers SaaS flexibilities. In a nutshell, the three main features of a snowflake are as follows:
Many fintech, technical and finance-related companies like AT&T, Cisco, Doordash, Greyhound, and Citi are using Snowflake as their data warehousing solution.
Snowflake is a data warehousing solution, its use cases comprise:
A Snowflake database can be used for the following three purposes:
There are three types of syntax to create a database in snowflake resonating with the above three purposes.
CREATE [ OR REPLACE ] [ TRANSIENT ] DATABASE [ IF NOT EXISTS ] <name>
[ CLONE <source_db>
[ { AT | BEFORE } ( { TIMESTAMP => <timestamp> | OFFSET => <time_difference> | STATEMENT => <id> } ) ] ]
[ DATA_RETENTION_TIME_IN_DAYS = <integer> ]
[ MAX_DATA_EXTENSION_TIME_IN_DAYS = <integer> ]
[ DEFAULT_DDL_COLLATION = ‘<collation_specification>‘ ]
[ [ WITH ] TAG ( <tag_name> = ‘<tag_value>‘ [ , <tag_name> = ‘<tag_value>‘ , … ] ) ]
[ COMMENT = ‘<string_literal>‘ ]
Where,
While cloning a database, the AT | BEFORE clause signifies the use of Time Travel to clone the database at or before a specific point in the past.
CREATE DATABASE <name> FROM SHARE <provider_account>.<share_name>
Where,
CREATE DATABASE <name>
AS REPLICA OF <account_identifier>.<primary_db_name>
[ DATA_RETENTION_TIME_IN_DAYS = <integer> ]
Where,
There are three types of tables in Snowflake. These three types are as follows:
Let’s understand them one by one.
With the Snowflake CREATE TABLE command, you can create a new table or replace an existing table. The table consists of multiple columns. To create a table you need a column name, the column data type, and optionally whether the column. A table in snowflake requires the following:
Besides the above-mentioned factors, this command also supports the following 4 variations:
The syntax for Create Table As Select in Snowflake
When you want to create a new table from an existing table schema and populate data resultant returned by a query, Create table as Select(CATS) is a good fit.
CREATE [ OR REPLACE ] TABLE <table_name> [ ( <col_name> [ <col_type> ] , <col_name> [ <col_type> ] , … ) ] [ CLUSTER BY ( <expr> [ , <expr> , … ] ) ] [ COPY GRANTS ] AS SELECT <query> [ … ]
The syntax for CREATE TABLE LIKE in Snowflake
When you want to create a replica of an existing table, CREATE TABLE LIKE is useful. It is used to create a new table with a similar column definition but no data copied from the existing table. Only column name, column data type, defaults, and constraints will be copied to the new table.
CREATE [ OR REPLACE ] TABLE <table_name> LIKE <source_table> [ CLUSTER BY ( <expr> [ , <expr> , … ] ) ] [ COPY GRANTS ] [ … ]
When you want to create a new table with a similar column definition as the source table and containing all the existing data from the source table, without actually copying the data, this variant can be used. You can use this command also to clone a table at a specific time/point in the past.
CREATE [ OR REPLACE ] TABLE <name> CLONE <source_table>
[ { AT | BEFORE } ( { TIMESTAMP => <timestamp> | OFFSET => <time_difference> | STATEMENT => <id> } ) ]
[ COPY GRANTS ]
[ … ]
Follow this article for further information.
In this blog, we talked about a brief introduction of Snowflake, its use case of it, and methods to create a database in snowflake along with the types of tables present in it. Moreover, you got an overview of methods to create various types of tables in Snowflake.
About Author
1 Comment