Sharing data from multiple databases (2024)

Snowflake data providers can share data from multiple databases by using secure views. A secure view can reference objects suchas schemas, tables, and other views contained in one or more databases, as long as those databases belong to the same account.

Sharing a secure view that references objects from multiple databases is different from sharing data contained in asingle database.

In addition to performing all the standard steps to share data, you must also grant the REFERENCE_USAGE privilegeon each database referenced by a secure view that you wish to share. However, you do not need to grant REFERENCE_USAGE on thedatabase that contains the secure view.

Note

You cannot use database roles to share data from multiple databases. You cannot grant the REFERENCE_USAGE privilege to adatabase role and you cannot use a database role to grant a secure viewthat references objects from multiple databases to a share.

You must grant the REFERENCE_USAGE privilege separately on each database referenced in a secure view, before granting thesecure view to a share.

To share a secure view that references objects from multiple databases:

  1. Connect to your Snowflake account as a user with the ACCOUNTADMIN role or a role granted the CREATE SHARE global privilege.For more details about the CREATE SHARE privilege, see Enabling non-ACCOUNTADMIN roles to perform data sharing tasks.

  2. Create a share using CREATE SHARE.

  3. Grant the USAGE privilege on the database you wish to share using GRANT <privilege> … TO SHARE.

    Note

    If you are sharing a secure view that references objects contained in multiple databases, you only need to grant the USAGE privilegeto the database where the secure view is created. You can only grant USAGE to one database per share.

    Granting the USAGE privilege to the database associates the share with a database, which is required to grant other privilegesto the share.

  4. Grant the USAGE privilege on each schema in the database you wish to share using GRANT <privilege> … TO SHARE.

  5. Grant the REFERENCE_USAGE privilege on each additional database that contains objects referenced by the view you wish to share usingGRANT <privilege> … TO SHARE.

  6. Add the view to the share by granting the SELECT privilege on the view using GRANT <privilege> … TO SHARE.

  7. Add one or more consumer accounts to the share using ALTER SHARE.

The share is now ready to be consumed by the specified accounts.

Note

To share a secure view that references a UDF in a different database, you must make the UDF secure. For more details about creating asecure UDF, see Creating a Secure UDF or Stored Procedure.

Examples

Refer to the following examples for creating secure views.

Sharing data from multiple database with consumers in other regions

You can share data from multiple databases with consumer accounts in other regions and cloud platforms by using a replication group.Include the share and each database the share references in the group to replicate data to a Snowflake account in another region.You can then add consumer accounts to the replicated share. For detailed instructions,see Sharing data securely across regions and cloud platforms.

Sharing data from multiple databases (2024)
Top Articles
Latest Posts
Article information

Author: Twana Towne Ret

Last Updated:

Views: 5978

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.