---
sidebar_position: 1
title: Sharing concepts and overview
description: MotherDuck data sharing model concepts including read-only shares and scope options.
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Sharing data in MotherDuck

MotherDuck's data sharing model has the following key characteristics:
- Sharing is at the granularity of a MotherDuck database.
- Sharing is read-only.
- Sharing is done through **share** objects.
- You can make shares discoverable and queryable by all users in your [Organization](../managing-organizations/managing-organizations.mdx).
- You can create restricted shares, where access to each is managed with an [Access Control List (ACL)](./sharing-with-users.md).
- Alternatively, you can use hidden share URLs to limit access to specific people in your organization you share the URL with.
    - You can also configure the URL of a hidden share to be accessible by anyone with a MotherDuck account in the same cloud region as your Organization.

:::note
Shares are **region-scoped** based on your Organization's cloud region. Each MotherDuck Organization is scoped to a single cloud region that must be chosen at Org creation when signing up.

MotherDuck is available on AWS in two regions:
- **US East (N. Virginia):** `us-east-1`
- **Europe (Frankfurt):** `eu-central-1`
:::

Sharing in MotherDuck works as follows:
1. The **data provider** shares their database in MotherDuck by creating a share.
2. The **data consumer** attaches said share, which creates a database clone in their workspace. The data consumer can now query this database.
3. The **data provider** periodically updates the share to push updates to the database to **data consumers**.

## Creating a share

The first step in sharing databases in MotherDuck is to create a share, which can be done in both UI and SQL. Creating a share does not incur additional costs, and no actual data is copied or transferred - creating a share is a zero-copy, metadata-only operation.
<Tabs>
<TabItem value="UI" label="UI">
Click on the "trident" next to the database you'd like to share. Select "share". Then:

![trident](./img/ui-share_new.png)

1. Optionally, choose a share name. Default will be the database name.
2. Choose whether the share should only be accessible by all users in your Organization, specified users in your Organization, or any MotherDuck user in the same cloud region who has access to the share link.
3. Choose whether the share should be automatically updated or not. Default is `MANUAL`

</TabItem>

<TabItem value="SQL" label="SQL">

The following example creates a share from database "birds":
- Share is also named "birds".
- This share can only be accessed by accounts authenticated in your [Organization](../managing-organizations/managing-organizations.mdx).
- This share is discoverable. Users in your Organization can find this share.

```sql
use birds;
CREATE SHARE; -- Shorthand syntax. Share name is optional. By default, shares are Organization-scoped and Discoverable. 
CREATE SHARE IF NOT EXISTS birds FROM birds
    (ACCESS ORGANIZATION , VISIBILITY DISCOVERABLE, UPDATE MANUAL); -- This query is identical to the previous one but with explicit options.
```

Learn more about the [CREATE SHARE](/sql-reference/motherduck-sql-reference/create-share.md) SQL command.

</TabItem>
</Tabs>


### Organization shares

When creating a share, you may choose scope of access to this share:
- **Organization**. Only users authenticated in your Organization will have access to this share.
- **Restricted**. Only the share owner and users specified with `GRANT` commands can access the share.
- **Unrestricted**. Any user signed into any MotherDuck organization in the same cloud region can access this share using the share URL.


### Discoverable shares

When creating a share, you may choose to make this share **Discoverable**. All authenticated users in your Organization can find this share in the UI.

You can create **Discoverable** shares that are **Unrestricted**, but only members of your Organization can find this share in the UI. Non-members can still access this share using the share URL.

### Share URLs

When you create a share, a URL for this share is generated:
- If the share is **Discoverable**, members of your Organization can find this share without the share URL. Alternatively, they can use the URL directly.
- If the share is **Hidden** (e.g. not Discoverable), other users will not be able to find the share URL. You will need to send this URL directly to the users with whom you want to share this data.



## Consuming shared data

The **data consumer** needs to attach the share to their workspace, thereby creating a read-only zero-copy clone of the source database. This is a free, metadata-only operation.

### Views and fully-qualified table references

If the shared database contains views, those views may reference tables using fully-qualified paths that include the original database name. For example, a view in a database called `org_dwh` might reference `org_dwh.main.sales`.

When you attach the share, make sure the database alias matches the original database name. Otherwise, the views fail because they can't resolve the original database name in your namespace.

```sql
-- The share was created from a database called "org_dwh".
-- Views inside reference the tables as "org_dwh.main.<table_name>".

-- This will cause view errors because the alias doesn't match:
ATTACH 'md:_share/org_dwh/id_abc123' AS dwh;

-- Use the original database name as the alias:
ATTACH 'md:_share/org_dwh/id_abc123' AS org_dwh;
```

This applies to any object in the shared database that uses fully-qualified references, including views, macros, and stored procedures.

### Consuming discoverable shares

If the **data provider** created a Discoverable share you have access to, you should be able to find this share in the UI.



<Tabs>
<TabItem value="UI" label="UI">
1. Select the share you want under "Shared with me".
2. Optionally roll over the share to see the tooltip that tells you the share owner, when it was last updated, and share access scope.
2. Click "attach".
3. You can query the resulting database.

</TabItem>

</Tabs>

### Consuming hidden shares

If the **data provider** created a Hidden (e.g. non-Discoverable) share, they need to pass the share URL to the **data consumer**. The **data consumer**, in turn, needs to attach the share URL.

```sql
ATTACH 'md:_share/ducks/0a9a026ec5a55946a9de39851087ed81' AS birds;   # attaches the share as database `birds`
```



## Updating shared data

If during creation of the share, the **data provider** chooses to have the share update automatically, the share will be updated periodically.
If the share was created with `MANUAL` updates, the **data provider** needs to manually update the share.

```sql
UPDATE SHARE birds; 
```

Learn more about [UPDATE SHARE](/sql-reference/motherduck-sql-reference/update-share.md) and [data replication timing and checkpoints](./updating-shares.md).


## Consuming updated data

By default, shares automatically update every minute. However, if you need the most up-to-date data sooner, the consumer can manually refresh the share after the producer executes UPDATE SHARE.

To manually refresh the data:

```sql
REFRESH DATABASES;       -- Refreshes all connected databases and shares
REFRESH DATABASE my_share;  -- Alternatively, refresh a specific database/share
```

Lean more about [REFRESH DATABASES](/sql-reference/motherduck-sql-reference/refresh-database.md).
