Share queries

This page describes how to share queries with users, groups, and service principals.

Query permissions and sharing settings

Queries support two types of sharing settings:

  • Run as viewer: The viewer’s credential is used to run the query. The viewer must also have at least CAN USE permissions on the warehouse.

    Users can only be granted the CAN EDIT permission when the sharing setting is set to Run as viewer.

  • Run as owner: The owner’s credential is used to run the query.

There are five permission levels for a query: NO PERMISSIONS, CAN VIEW, CAN RUN, CAN EDIT, and CAN MANAGE. The table lists the abilities for each permission.

Ability

NO PERMISSIONS

CAN VIEW

CAN RUN

CAN EDIT

CAN MANAGE

View own queries

x

x

x

x

See in query list

x

x

x

x

View query text

x

x

x

x

View query result

x

x

x

x

Refresh query result (or choose different parameters)

x

x

x

Include the query in a dashboard

x

x

x

Edit query text

x

x

Change SQL warehouse or data source

x

Modify permissions

x

Delete query

x

Workspace admins have the CAN MANAGE permission on all queries in their workspace. Users automatically have the CAN MANAGE permission for queries they create.

Note

The principal used to run a query is the user that created the query, not the user that clicks the Refresh button.

Share a query

You must have at least CAN MANAGE permission on a query to share queries. You can also manage permissions using the Permissions API or the Databricks Terraform provider.

  1. In the sidebar, click Queries.

  2. Click a query.

  3. Click the Share Button button at the top right to open the Sharing dialog.

    Manage query permissions
  4. Follow the steps based on the permission type you want to grant:

  5. Search for and select the groups, users, and service principals, and assign the permission level.

  6. Click Add.

  7. In the Sharing settings > Credentials field at the bottom, select either Run as viewer or Run as owner.

You can also copy the link to the query in the Sharing dialog.

Manage query permissions with folders

You can manage query permissions by adding queries to folders. Queries in a folder inherit the permissions settings of that folder. For example, a user that has CAN RUN permission on a folder has CAN RUN permission on the queries in that folder.

However, if a query is shared with the Run as Owner privilege and shared in a folder where multiple users have CAN EDIT or CAN MANAGE access, those permissions are downgraded to prevent users from editing the query text itself. Only the query owner can modify the query, while other users with CAN MANAGE access can still read, delete, and run the query.

To learn about configuring permissions on folders, see Folder permissions.

To learn more about organizing queries into folders, see Workspace browser.

Transfer ownership of a query

You must be a workspace admin to transfer ownership of a query. Service principals and groups cannot be assigned ownership of a query. You can also transfer ownership using the Permissions API.

  1. As a workspace admin, log in to your Databricks workspace.

  2. In the sidebar, click Queries.

  3. Click a query.

  4. Click the Share button at the top right to open the Sharing dialog.

  5. Click on the gear icon at the top right and click Assign new owner.

    Assign new owner
  6. Select the user to assign ownership to.

  7. Click Confirm.