Crie esquemas
Este artigo mostra como criar esquemas em Unity Catalog e no legado Hive metastore.
Para saber mais sobre esquemas em Databricks, incluindo uma comparação do comportamento do esquema em Unity Catalog e Hive metastore, consulte O que são esquemas em Databricks?
Antes de começar
Para criar um esquema no Unity Catalog:
- O senhor deve ter um metastore Unity Catalog vinculado ao workspace onde realiza a criação do esquema.
- Você deve ter as permissões de dados
USE CATALOG
eCREATE SCHEMA
no catálogo principal do esquema. Tanto o administrador da metastore quanto o proprietário do catálogo podem conceder esses privilégios a você. Se você for administrador da metastore, poderá conceder esses privilégios a si mesmo. - Para especificar um local de armazenamento gerenciar opcional para as tabelas e os volumes no esquema, um local externo deve ser definido em Unity Catalog e o senhor deve ter o privilégio
CREATE MANAGED STORAGE
no local externo. Consulte Especificar um local de armazenamento gerenciar em Unity Catalog. - O clustering que o senhor usa para executar um Notebook para criar um esquema deve usar um modo de acesso compatível com o Unity Catalog. Consulte Modos de acesso. SQL O armazém sempre oferece suporte ao site Unity Catalog.
Para criar um esquema em Hive metastore:
- As permissões necessárias dependem do fato de o senhor estar usando o controle de acesso da tabela. Consulte Hive metastore privileges and securable objects (legacy).
Crie um esquema
Para criar um esquema em Unity Catalog, o senhor pode usar o Catalog Explorer ou o comando SQL. Para criar um esquema em Hive metastore, o senhor deve usar o comando SQL.
- 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 you want to create the schema in.
- In the detail pane, click Create schema.
- Give the schema a name and add any comment that would help users understand the purpose of the schema.
- (Optional) Specify a managed storage location. Requires the
CREATE MANAGED STORAGE
privilege on the target external location. See Specify a managed storage location in Unity Catalog and Managed locations for schemas. - Click Create.
- Grant privileges on the schema. See Manage privileges in Unity Catalog.
- Click Save.
-
Run the following SQL commands in a notebook or the SQL query editor. Items in brackets are optional. You can use either
SCHEMA
orDATABASE
. Replace the placeholder values:<catalog-name>
: The name of the parent catalog for the schema. If you are creating a schema in Hive metastore and you are in a Unity Catalog-enabled workspace, usehive_metastore
as the catalog name. If your workspace is not enabled for Unity Catalog, don’t specify a catalog at all.<schema-name>
: A name for the schema.<location-path>
: Optional path to a managed storage location. Use withMANAGED LOCATION
for Unity Catalog and withLOCATION
for Hive metastore. In Unity Catalog, you must have theCREATE MANAGED STORAGE
privilege on the external location for the path that you specify. See Specify a managed storage location in Unity Catalog and Managed locations for schemas.<comment>
: Optional description or other comment.<property-key> = <property-value> [ , ... ]
: Optional. Spark SQL properties and values to set for the schema.
For more detailed parameter descriptions, see CREATE SCHEMA.
SQLCREATE { DATABASE | SCHEMA } [ IF NOT EXISTS ] <catalog-name>.<schema-name>
[ MANAGED LOCATION '<location-path>' | LOCATION '<location-path>']
[ COMMENT <comment> ]
[ WITH DBPROPERTIES ( <property-key = property_value [ , ... ]> ) ]; -
Grant privileges on the schema. For Unity Catalog privileges, see Manage privileges in Unity Catalog.
O senhor também pode criar um esquema usando o provedor Databricks Terraform e databricks_schema. Você pode recuperar uma lista de IDs de esquema usando databricks_schemas
Próximas etapas
- Para saber como adicionar tabelas, visualizações e volumes ao seu esquema, consulte O que é uma tabela?, O que é um view? e O que são volumes Unity Catalog?
- Para saber como adicionar modelos AI ao seu esquema, consulte gerenciar o ciclo de vida do modelo em Unity Catalog.
- Para saber como view, atualizar e eliminar esquemas existentes, consulte gerenciar esquemas.