SET TAG

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 16.1 and above

Sets a tag on a catalog, schema, table, view, volume, column, function, or external metadata object.

Important

Setting tags on external metadata objects is in Public Preview and requires Databricks Runtime 18.2 or above.

To add tags to Unity Catalog securable objects, you must own the object or have all of the following privileges:

  • APPLY TAG on the object
  • USE SCHEMA on the object's parent schema
  • USE CATALOG on the object's parent catalog

External metadata objects are not contained in a catalog or schema, so USE CATALOG and USE SCHEMA do not apply.

If the tag is governed you also need ASSIGN permission on the governed tag

Syntax

SET TAG ON
    { CATALOG catalog_name |
      COLUMN relation_name . column_name |
      EXTERNAL METADATA external_metadata_name |
      { FUNCTION | PROCEDURE } function_name |
      { SCHEMA | DATABASE } schema_name |
      TABLE relation_name |
      VIEW  relation_name |
      VOLUME volume_name }
    tag_key [ = tag_value ]

Parameters

  • CATALOG catalog_name

    The name of the catalog to tag.

  • COLUMN relation_name . column_name

    The qualified name of the column to tag. relation_name must identify a view or a table. The relation_name must not include a temporal specification or options specification.

  • EXTERNAL METADATA external_metadata_name

    The name of the external metadata object to tag.

  • { FUNCTION | PROCEDURE } function_name

    The name of the function or procedure to tag. FUNCTION and PROCEDURE are interchangeable.

    Note

    Tagging functions and procedures requires Databricks Runtime 18.1 or above.

  • SCHEMA schema_name

    The name of the schema to tag.

  • TABLE relation_name

    The name of the table or view to tag. The name must not include a temporal specification or options specification.

  • VIEW relation_name

    The name of the view to tag.

  • VOLUME volume_name

    The name of the volume to tag.

  • tag_key

    An identifier. If a tag assignment with the same key already exists and exception is raised.

  • tag_value

    An optional identifier. If not specified, the tag assignment will be set as key-only.

Examples

> SET TAG ON CATALOG catalog `cost_center` = `hr`;

> UNSET TAG ON CATALOG catalog cost_center;

> SET TAG ON TABLE catalog.schema.table cost_center = hr;

> UNSET TAG ON TABLE catalog.schema.table cost_center;

> SET TAG ON COLUMN table.ssn pii;

> UNSET TAG ON COLUMN table.ssn pii;

> SET TAG ON FUNCTION catalog.schema.my_func cost_center = hr;

> UNSET TAG ON FUNCTION catalog.schema.my_func cost_center;

> SELECT catalog_name, schema_name, table_name, tag_name, tag_value
    FROM information_schema.column_tags
    WHERE tag_name = 'pii' AND schema_name = 'default';
  table_name column_name
  ---------- -----------
  table      ssn