スキーマの管理
この記事では、Unity Catalog でスキーマを表示、更新、および削除する方法について説明します。
「Databricks のスキーマとは」および「スキーマを作成する」も参照してください。
Hive metastoreでは、SQL コマンドを使用してスキーマを管理する必要があります。従来の Hive metastore での動作は、 Unity Catalogとは異なります。 必要な権限は、テーブルアクセスコントロールを使用しているかどうかによって異なります。 Hive metastoreのスキーマとHive metastore特権およびセキュリティ保護可能なオブジェクト (レガシ)を参照してください。
始める前に
Unity Catalog でスキーマを操作するには:
- スキーマの作成を実行する ワークスペースにリンクされた Unity Catalog メタストアが必要です。
- ノートブックを実行してスキーマを管理するために使用するクラスターでは、Unity Catalog 準拠のアクセスモードを使用する必要があります。 「アクセスモード」を参照してください。SQLウェアハウスは常に Unity Catalogをサポートしています。
- Unity Catalog でスキーマを変更、表示、およびドロップするために必要なアクセス許可については、次のセクションに一覧表示します。
スキーマの検索と表示
Unity Catalog では、ユーザーは USE SCHEMA
アクセス許可が割り当てられているすべてのスキーマと、スキーマの親カタログの USE CATALOG
アクセス許可を表示できます。 スキーマ内のテーブルまたはビューにアクセスしたり、リストしたりするには、テーブルまたはビューに対する SELECT
権限も必要です。
- Catalog Explorer
- SQL
- Log in to a workspace that is linked to the Unity Catalog metastore.
- Click
Catalog.
- In the Catalog pane on the left, click the catalog that contains the schema (
hive_metastore
if it’s in the Hive metastore).
Alternatively, you can search for the schema using the Type to filter field in the Catalog pane.
Run SHOW SCHEMAS
in a notebook or the SQL query editor to list all schemas in a catalog or those that match a regular expression. Run DESCRIBE SCHEMA
to get details about a schema. See SHOW SCHEMAS and DESCRIBE SCHEMA.
スキーマを更新する
Unity Catalog カタログのスキーマを更新 (または変更) するには、Catalog Explorer または SQL コマンドを使用できます。
必要なアクセス許可 : Unity Catalog でスキーマを更新するために必要なアクセス許可は、更新によって異なります。
- 所有者を変更するには、自分が所有者であるか、スキーマに
MANAGE
とUSE SCHEMA
があり、親カタログにUSE CATALOG
ている必要があります。 - スキーマの名前を変更するには、所有者であるか、スキーマに
MANAGE
とUSE SCHEMA
があり、親カタログにUSE CATALOG
ている必要があります。 - コメントを追加または更新するには、所有者であるか、スキーマと親カタログの
USE CATALOG``USE SCHEMA
とMANAGE
またはMODIFY
を持っている必要があります。 - タグを追加または更新するには、所有者であるか、スキーマに
USE SCHEMA
とMODIFY
があり、親カタログにUSE CATALOG
ている必要があります。 - テーブルを追加するには、スキーマの所有者であるか、スキーマに
USE SCHEMA
とCREATE TABLE
があり、親カタログにUSE CATALOG
ている必要があります。 - ボリュームを追加するには、スキーマの所有者であるか、スキーマに
USE SCHEMA
とCREATE VOLUME
があり、親カタログにUSE CATALOG
ている必要があります。 - スキーマに対するアクセス許可を付与および取り消すには、スキーマの所有者、親カタログの所有者、メタストア管理者であるか、スキーマに対する
MANAGE
とUSE SCHEMA
、親カタログに対するUSE CATALOG
を持っている必要があります。
- Catalog Explorer
- SQL
-
Log into a workspace that is linked to the Unity Catalog metastore.
-
Click
Catalog.
-
In the Catalog pane on the left, click the catalog that contains the schema and then click the schema to open the schema details page.
Alternatively, you can search for the schema using the Type to filter field in the Catalog pane.
-
Use the following page elements on the schema details page to update the schema:
- Overview tab: update the owner, add or update tags, add or update comments. See Manage Unity Catalog object ownership, Apply tags to Unity Catalog securable objects, and Add comments to data and AI assets.
- Permissions tab: grant and revoke privileges on the schema. See Manage privileges in Unity Catalog.
- The
kebab menu: Rename the schema.
- Create button: create a table or volume in the schema. See Create or modify a table using file upload and What are Unity Catalog volumes?.
- To change the owner, add or update tags, set schema properties, and manage predictive optimization on the tables in a schema, run the
ALTER SCHEMA
command in a notebook or the SQL query editor. See ALTER SCHEMA. - To grant or revoke privileges, use the
GRANT
orREVOKE
command. See GRANT and REVOKE. - To add tables, volumes, and other data and AI assets to a schema, see the documentation for creating the asset (for example What is a table? or Manage model lifecycle in Unity Catalog).
- To rename a schema using SQL, you must create a new schema and move all assets into the new schema.
スキーマを削除する
Unity Catalog カタログ内のスキーマを削除 (または削除) するには、Catalog Explorer または SQL コマンドを使用できます。
必要なアクセス許可 : Unity Catalog にスキーマを削除するには、その所有者である必要があります。
- Catalog Explorer
- SQL
You must delete all tables in the schema before you can delete it.
- Log in to a workspace that is linked to the metastore.
- Click
Catalog.
- In the Catalog pane, on the left, click the schema that you want to delete.
- In the detail pane, click the kebab menu
in the upper right corner and select Delete.
- On the Delete schema dialog, click Delete.
Run the following SQL command in a notebook or the SQL query editor. Items in brackets are optional. Replace the placeholder <schema-name>
.
For parameter descriptions, see DROP SCHEMA.
If you use DROP SCHEMA
without the CASCADE
option, you must delete all tables in the schema before you can delete it.
DROP SCHEMA [ IF EXISTS ] <schema-name> [ RESTRICT | CASCADE ]
For example, to delete a schema named inventory_schema
and its tables:
DROP SCHEMA inventory_schema CASCADE
次のステップ
スキーマにテーブルとボリュームを追加する方法については、「 テーブルとは」を参照してください。 およびUnity Catalog ボリュームとは。