← Back to Tutorials

12. Database

-- Create
CREATE DATABASE sales_db;

-- Clone (zero-copy)
CREATE DATABASE sales_dev_db CLONE sales_db;

-- Drop
DROP DATABASE IF EXISTS sales_dev_db;

-- Undrop (time travel recovery)
UNDROP DATABASE sales_dev_db;

-- Set data retention
ALTER DATABASE sales_db SET DATA_RETENTION_TIME_IN_DAYS = 30;

Zero-Copy Cloning

Creates a copy of the database that shares the underlying storage until changes are made. No additional storage cost for the clone until you modify data.

Sharing

Create a share for secure data sharing between accounts:

CREATE SHARE sales_share;
GRANT USAGE ON DATABASE sales_db TO SHARE sales_share;
ALTER SHARE sales_share ADD ACCOUNTS = another_account;
✏️ Exercise: Create a database, clone it, verify the clone is identical. Drop the clone, then undrop it.