ALTER SHARE (Databricks SQL)

Preview

Delta Sharing is in Public Preview. To participate in the preview, you must enable the External Data Sharing feature group in the Databricks Account Console. See Enable the External Data Sharing feature group for your account.

Delta Sharing is subject to applicable terms. Enabling the External Data Sharing feature group represents acceptance of those terms.

Adds or removes tables to or from the share. Transfers the ownership of a share to a new principal.

Syntax

ALTER share_name
  { alter_table |
    REMOVE TABLE clause }

alter_table
  { ADD [ TABLE ] table_name [ COMMENT comment ]
        [ PARTITION clause ] [ AS table_share_name ]
        [ WITH CHANGE DATA FEED ] }

Parameters

  • share_name

    The name of the share to be altered.

  • alter_table

    Adds a table or partitions of a table to the share.

    • ADD [ TABLE ] table_name

      Identifies the table to be added. The table must not reside in the hive_metastore.

    • COMMENT comment

      An optional string literal attached to the table share as a comment.

    • PARTITION clause

      One or to more partitions of the table to be added. The partition keys must match the partitioning of the table and be associated with values. If no PARTITION clause is present ADD TABLE adds the entire table.

    • AS table_share_name

      Optionally exposes the table under a different name. The name can be qualified with a database (schema) name. If no table_share_name is specified the table will be known under its own name.

    • WITH CHANGE DATA FEED

      Requires: SQL warehouse version 2022.30 or higher. This version is available in the Preview channel.

      Optionally specifies that the share gets access to the change data feed of the Delta Lake table. A shared table WITH CHANGE DATA FEED can be referenced by the table_changes() function to view the history of changes to the shared table. The shared table can also be referenced using VERSION AS OF temporal specification.

  • REMOVE [ TABLE ] table_name

    Remove the table identified by table_name from the share.

Examples

-- Creates a share named `some_share`.
> CREATE SHARE some_share;

-- Add a table to the share.
> ALTER SHARE some_share
     ADD TABLE my_schema.my_tab
         COMMENT 'some comment'
         PARTITION(c1_int = 5, c2_date LIKE '2021%')
         AS shared_schema.shared_tab;

-- Add a table with data change feed to the share.
> ALTER SHARE some_share
     ADD TABLE my_schema.my_tab1 WITH DATA CHANGE FEED;

-- Remove the table again
> ALTER SHARE some_share
    REMOVE TABLE shared_schema.shared_tab;