In our last post, we discussed what is known as “Zero-Copy Cloning” in Snowflake. We were able to copy a table without taking up any space and extremely quickly with one short command!
Now, I know what you’re thinking…
One table at a time. Now I know what you’re thinking “Copying some of my databases would take forever…”
Well, don’t fret, my friends! Snowflake has a way!
CREATE SCHEMA ARAccounts CLONE APAccounts;
Yes, that’s right. With the above command, you will copy all objects contained within the schema.
Yes, you read that right.
All stored procedures. All tables. All views. All tasks. All functions. Pretty much, you name it. It’s cloned for you.
The only objects that are not clonable (at least as of the creation of this post) are the following:
- Internal Named Stages
- External Tables
- Objects that are in both a failover group and a replication group
- Secondary objects added to a primary replication or failover group
- Inbound shares
Yes, that’s right. An amazingly short list for objects that cannot be cloned with one small command.
Now, yes, you can copy each of these objects over individually if needed. Thankfully, it uses the same basic structure for each object.
CREATE OR REPLACE DATABASE DatabaseB CLONE DatabaseA;
CREATE OR REPLACE TASK TaskB CLONE TaskA;
As always, be careful using the “OR REPLACE” portion of this command because you can accidentally clone over an object in use. And little will wake you up like accidentally cloning over an object in Production that is in use.
And with that, we have come yet again to the end of our time together. Hopefully, you’ve learned a little bit more about cloning and cannot wait for next time when we’ll delve a bit more into cloning objects. Until then…