0
0
Snowflakecloud~5 mins

Zero-copy cloning in Snowflake - Commands & Configuration

Choose your learning style9 modes available
Introduction
Zero-copy cloning lets you make a copy of a database or table instantly without using extra storage. It solves the problem of waiting and paying for full copies by sharing the original data behind the scenes.
When you want to test changes on a database without affecting the original data.
When you need a quick backup of a table for analysis without extra storage costs.
When you want to create multiple environments (dev, test) from the same data instantly.
When you want to save storage by avoiding full data duplication.
When you want to experiment with data transformations safely.
Commands
This command creates a new database called 'mydb_clone' as a zero-copy clone of the existing 'mydb'. It instantly copies the structure and data without extra storage.
Terminal
CREATE DATABASE mydb_clone CLONE mydb;
Expected OutputExpected
Database MYDB_CLONE successfully created.
This command verifies that the cloned database 'mydb_clone' exists and is ready to use.
Terminal
SHOW DATABASES LIKE 'mydb_clone';
Expected OutputExpected
name | created_on | owner MYDB_CLONE | 2024-06-01 12:00:00 | USER_NAME
This command switches the session to use the cloned database so you can run queries or changes on it.
Terminal
USE DATABASE mydb_clone;
Expected OutputExpected
Database changed.
This command checks the number of rows in a table inside the cloned database to confirm data is accessible.
Terminal
SELECT COUNT(*) FROM mytable;
Expected OutputExpected
COUNT(*) 1000
Key Concept

If you remember nothing else from zero-copy cloning, remember: it creates instant copies without extra storage by sharing the original data behind the scenes.

Common Mistakes
Trying to clone a database that does not exist.
The clone command fails because there is no source database to copy from.
Make sure the source database exists before running the clone command.
Assuming changes in the clone affect the original database.
Clones are independent after creation; changes do not reflect back to the original.
Treat the clone as a separate database for changes and testing.
Expecting the clone to use the same storage as the original after many changes.
Over time, changes in the clone consume additional storage as data diverges.
Monitor storage usage if clones are heavily modified.
Summary
Use CREATE DATABASE ... CLONE to make an instant copy without extra storage.
Verify the clone exists with SHOW DATABASES and switch to it with USE DATABASE.
Query the clone like a normal database; changes do not affect the original.