Create schemas
This article shows how to create schemas in Unity Catalog and the legacy Hive metastore.
To learn about schemas in Azure Databricks, including a comparison of schema behavior in Unity Catalog and Hive metastore, see What are schemas in Azure Databricks?.
Before you begin
To create a schema in Unity Catalog:
- You must have a Unity Catalog metastore linked to the workspace where you perform the schema creation.
- You must have the
USE CATALOG
andCREATE SCHEMA
data permissions on the schema's parent catalog. Either a metastore admin or the owner of the catalog can grant you these privileges. If you are a metastore admin, you can grant these privileges to yourself. - To specify an optional managed storage location for the tables and volumes in the schema, an external location must be defined in Unity Catalog, and you must have the
CREATE MANAGED STORAGE
privilege on the external location. See Specify a managed storage location in Unity Catalog. - The cluster that you use to run a notebook to create a schema must use a Unity Catalog-compliant access mode. See Access modes. SQL warehouses always support Unity Catalog.
To create a schema in Hive metastore:
- Permissions required depend on whether you are using table access control. See Hive metastore privileges and securable objects (legacy).
Create a schema
To create a schema in Unity Catalog, you can use Catalog Explorer or SQL commands. To create a schema in Hive metastore, you must use SQL commands.
Catalog Explorer
- 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.
SQL
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.
CREATE { 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.
You can also create a schema by using the Databricks Terraform provider and databricks_schema. You can retrieve a list of schema IDs by using databricks_schemas
Next steps
- To learn how to add tables, views, and volumes to your schema, see What is a table?, What is a view?, and What are Unity Catalog volumes?.
- To learn how to add AI models to your schema, see Manage model lifecycle in Unity Catalog.
- To learn how to view, update, and drop existing schemas, see Manage schemas.