0
0
Snowflakecloud~5 mins

Clone use cases (dev, testing, backups) in Snowflake - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need a quick copy of your database to try new ideas, test changes, or keep a backup without using extra space. Snowflake cloning lets you do this instantly and efficiently.
When a developer wants to try new code on a copy of the production data without affecting the original.
When testers need a safe environment with real data to check if new features work correctly.
When you want to create a backup snapshot of your database before making big changes.
When you want to create multiple copies of a dataset for different teams without extra storage costs.
When you want to quickly restore data to a previous state by cloning an earlier version.
Commands
This command creates a new database called 'dev_clone' as an instant copy of 'production_db'. Developers can use this clone to work safely without changing the original data.
Terminal
CREATE DATABASE dev_clone CLONE production_db;
Expected OutputExpected
Database DEV_CLONE successfully created.
This command checks that the 'dev_clone' database exists and is ready to use.
Terminal
SHOW DATABASES LIKE 'DEV_CLONE';
Expected OutputExpected
name | created_on | owner DEV_CLONE | 2024-06-01 12:00:00 | USER_NAME
This creates a clone named 'test_clone' for testing purposes, so testers can verify new features without risk.
Terminal
CREATE DATABASE test_clone CLONE production_db;
Expected OutputExpected
Database TEST_CLONE successfully created.
This command makes a backup clone called 'backup_clone' to keep a snapshot of the current production data.
Terminal
CREATE DATABASE backup_clone CLONE production_db;
Expected OutputExpected
Database BACKUP_CLONE successfully created.
When the development work is done, this command removes the 'dev_clone' database to free up resources.
Terminal
DROP DATABASE dev_clone;
Expected OutputExpected
Database DEV_CLONE dropped.
Key Concept

If you remember nothing else from this pattern, remember: Snowflake clones let you instantly copy databases without extra storage, perfect for safe development, testing, and backups.

Common Mistakes
Trying to clone a database that does not exist.
The command fails because there is no source database to copy.
Check the source database name carefully before cloning.
Modifying the original database instead of the clone during testing.
Changes affect production data, causing potential errors or data loss.
Always connect to and work within the cloned database for safe testing.
Not dropping clones after use, leading to clutter.
Unused clones can cause confusion and use system resources.
Drop clones when they are no longer needed to keep your environment clean.
Summary
Use CREATE DATABASE ... CLONE to make instant copies of databases for development, testing, or backups.
Verify clones exist with SHOW DATABASES to ensure they are ready for use.
Drop clones with DROP DATABASE when finished to keep your workspace tidy.