This project demonstrates the use of Snowflake features for table cloning and table swapping. Cloning allows you to create an independent copy of a table instantly without duplicating data, while swapping lets you interchange table data, useful for ETL pipelines or staging environments.
Objective:
Create a table, load data from S3, clone it, and verify data.
Steps:
- Use the demo warehouse for executing all SQL commands.
- Create a database named
sales_clone_db
. - Create a table
sales_data_original
with the following columns:order_id
(Integer)customer_id
(Integer)customer_name
(String, 100 characters)order_date
(Date)product
(String, 100 characters)quantity
(Integer)price
(Numeric)complete_address
(String, 255 characters)
- Set up an external stage pointing to the S3 bucket containing the sales data.
- Load data from the stage into
sales_data_original
. - Create a cloned table named
sales_data_clone
based onsales_data_original
. - Query both
sales_data_original
andsales_data_clone
to verify data. - Clean up by dropping the tables, stage, and database.
Objective:
Swap data between two tables to demonstrate ETL/staging operations.
Steps:
- Use the demo warehouse to execute all SQL commands.
- Create a database named
swap_db
. - Create two tables:
current_sales
with columns:order_id
,customer_id
,product
(50 characters),quantity
staging_sales
with columns:order_id
,customer_id
,product
(50 characters),quantity
- Load sample data into both tables.
- Use the
SWAP
command to exchange data betweencurrent_sales
andstaging_sales
. - Query both tables to verify that the swap was successful.
- Clean up by dropping the tables and database.
- Cloned Tables: Useful for testing, backup, or creating independent versions of production tables without affecting the original data.
- Swapping Tables: Enables seamless replacement of production tables with staged data in ETL workflows, minimizing downtime.
- S3 Integration: Loading data from cloud storage allows centralized data management and reduces dependency on local files.