Bird
Raised Fist0
SnowflakeHow-ToBeginner · 4 min read

How to Use Secure Data Sharing in Snowflake: Step-by-Step Guide

To use secure data sharing in Snowflake, create a share object that references specific database objects and grant access to other Snowflake accounts without copying data. This allows real-time, secure access to live data while maintaining control and security.
📐

Syntax

Secure data sharing in Snowflake uses the CREATE SHARE command to define a share, then you add database objects like tables or views to it. Finally, you grant access to other accounts with GRANT USAGE and ALTER SHARE ADD ACCOUNTS.

  • CREATE SHARE <share_name>: Creates a new share object.
  • GRANT USAGE ON DATABASE <db_name> TO SHARE <share_name>: Allows the share to access the database.
  • GRANT SELECT ON TABLE <table_name> TO SHARE <share_name>: Shares specific tables.
  • ALTER SHARE <share_name> ADD ACCOUNTS = (<account_list>): Grants access to other Snowflake accounts.
sql
CREATE SHARE my_secure_share;
GRANT USAGE ON DATABASE my_database TO SHARE my_secure_share;
GRANT SELECT ON TABLE my_database.my_schema.my_table TO SHARE my_secure_share;
ALTER SHARE my_secure_share ADD ACCOUNTS = ('target_account');
💻

Example

This example shows how to create a secure share named sales_share that shares a sales table with another Snowflake account 123456789012. The target account can query the shared data without copying it.

sql
CREATE SHARE sales_share;
GRANT USAGE ON DATABASE sales_db TO SHARE sales_share;
GRANT SELECT ON TABLE sales_db.public.sales_data TO SHARE sales_share;
ALTER SHARE sales_share ADD ACCOUNTS = ('123456789012');
Output
Share SALES_SHARE created. Usage granted on database SALES_DB. Select granted on table SALES_DB.PUBLIC.SALES_DATA. Accounts added to share SALES_SHARE.
⚠️

Common Pitfalls

Common mistakes when using secure data sharing include:

  • Not granting USAGE on the database or schema to the share, causing access errors.
  • Forgetting to add the target account to the share with ALTER SHARE ADD ACCOUNTS.
  • Trying to share unsupported objects like stages or pipes.
  • Assuming data is copied; shared data is live and changes reflect immediately.
sql
/* Wrong: Missing USAGE grant on database */
CREATE SHARE bad_share;
GRANT SELECT ON TABLE sales_db.public.sales_data TO SHARE bad_share;
ALTER SHARE bad_share ADD ACCOUNTS = ('123456789012');

/* Right: Include USAGE grant */
CREATE SHARE good_share;
GRANT USAGE ON DATABASE sales_db TO SHARE good_share;
GRANT SELECT ON TABLE sales_db.public.sales_data TO SHARE good_share;
ALTER SHARE good_share ADD ACCOUNTS = ('123456789012');
📊

Quick Reference

CommandPurpose
CREATE SHARE Create a new secure share object
GRANT USAGE ON DATABASE TO SHARE Allow share to access database
GRANT SELECT ON TABLE TO SHARE Share specific table data
ALTER SHARE ADD ACCOUNTS = ()Grant access to other Snowflake accounts
SHOW SHARESList all shares in your account
DROP SHARE Remove a share when no longer needed
✅

Key Takeaways

Create a share and grant usage on database and tables to share data securely.
Add target Snowflake accounts to the share to allow access without data copying.
Shared data is live and updates immediately for consumers.
Always grant USAGE on database and schema to avoid access errors.
Secure data sharing supports controlled, real-time data access across accounts.