Sub topic 4
The three-level namespace
This chapter assumes you can write basic SQL (CREATE, SELECT, INSERT), you can run statements in a Databricks notebook or the SQL editor, and you know that tables are stored as files in cloud object storage. It also assumes you know what a metastore is from the previous chapters. Here you learn how Unity Catalog names objects, how to resolve names, and which mistakes cause the most errors.
Why three levels
Many older SQL systems name a table with two parts: database.table. Unity Catalog adds one level above that. Every table, view, or volume is addressed by three parts:
catalog.schema.objectThe extra level matters because one metastore usually serves many teams and environments. A catalog gives you a place to separate them, for example dev, test, and prod, or one catalog per business domain. Names only need to be unique within their parent. A schema called sales can exist in both dev and prod without conflict.
The namespace is also the structure that privileges follow. Permissions granted on a parent object apply to its children, so the way you name and nest objects decides how you secure them. Inheritance gets its own chapter. For now, keep in mind that the hierarchy is both a naming scheme and a security scheme.
The hierarchy
The metastore is the top-level container. It is not part of the name you type. Inside it, objects nest like this:
The table below summarizes each level.
| Level | Part of the name? | Contains | Example |
|---|---|---|---|
| Metastore | No | Catalogs | One per cloud region, attached to workspaces |
| Catalog | Yes, first part | Schemas | `dev` |
| Schema | Yes, second part | Tables, views, volumes, functions | `dev.sales` |
| Table or other object | Yes, third part | Data or logic | `dev.sales.orders` |
A name that spells out all three parts is called a fully qualified name. The first two parts together (dev.sales) identify a schema, and the first part alone identifies a catalog.
Creating the hierarchy
You create each level with its own statement. The following code builds a catalog, a schema inside it, and a managed table.
CREATE CATALOG IF NOT EXISTS dev;
CREATE SCHEMA IF NOT EXISTS dev.sales;
CREATE TABLE IF NOT EXISTS dev.sales.orders (
order_id BIGINT,
customer_id BIGINT,
order_ts TIMESTAMP,
amount DECIMAL(10,2)
);Notice that the schema statement already uses a two-part name, dev.sales, and the table statement uses three parts. You must create the parent before the child. Running the table statement before the schema exists fails with a "schema not found" style error.
CREATE CATALOG needs the CREATE CATALOG privilege on the metastore. CREATE SCHEMA needs CREATE SCHEMA on the catalog, and CREATE TABLE needs CREATE TABLE on the schema (plus USE CATALOG and USE SCHEMA on the parents). If a statement fails with a permission error, check which level you lack rights on.
Using fully qualified names
Once the table exists, you can write to it and read from it with the three-part name.
INSERT INTO dev.sales.orders VALUES
(1, 100, TIMESTAMP'2026-01-15 09:30:00', 25.50),
(2, 101, TIMESTAMP'2026-01-15 10:05:00', 80.00);
SELECT customer_id, SUM(amount) AS total_amount
FROM dev.sales.orders
GROUP BY customer_id;Fully qualified names have one big advantage: they mean the same thing no matter who runs them or where. A scheduled job, a notebook, and a colleague's query all reach the same table. For production jobs, shared code, and anything that is saved and rerun, prefer them.
Short names and the current catalog and schema
Typing three parts every time is tedious in exploratory work. Each session has a current catalog and a current schema. When you write a name with fewer than three parts, Unity Catalog fills in the missing parts from them.
USE CATALOG dev;
USE SCHEMA sales;
SELECT * FROM orders;After these two statements, orders resolves to dev.sales.orders. The resolution rules are:
- A three-part name is used as written.
- A two-part name
a.bis read asschema.objectin the current catalog. - A one-part name is read as an object in the current catalog and current schema.
You can check what a session currently uses with SELECT current_catalog(), current_schema();.
The defaults come from several places. A session starts with a default catalog set by the workspace or compute settings, and USE CATALOG and USE SCHEMA change it for the rest of the session. Because these defaults can differ between workspaces, clusters, and job configurations, the same short name can point to different tables in different places.
Common errors
Most namespace problems fall into a few patterns.
- Two-part name read in the wrong catalog. You write
sales.ordersexpectingprod, but the current catalog isdev, so you readdev.sales.orders. Checkcurrent_catalog()first. - Table or view not found. The name is spelled right, but the current schema is not what you think. Try the full three-part name. If that works, the defaults were the problem.
- Missing parent privileges. You have
SELECTon the table but still get a denial. Access to an object also needsUSE CATALOGon its catalog andUSE SCHEMAon its schema. The namespace levels are checked one after another. - Special characters in names. Names with hyphens, spaces, or other special characters must be wrapped in backticks, as in `
my-catalog.my schema.orders`. Simple names made of letters, digits, and underscores need no quoting. Avoiding special characters saves trouble. - Mixing up a database and a schema. In Databricks SQL,
DATABASEandSCHEMAare synonyms. A schema is the second level, never a separate system.
Names, case, and the legacy catalog
Object names in Unity Catalog are not case sensitive for lookup, and they are stored in lowercase. Dev.Sales.Orders and dev.sales.orders reach the same table. Still, pick one style, usually lowercase with underscores, so that code is easy to read and search.
Workspaces that existed before Unity Catalog have a catalog called hive_metastore, which holds the older two-level tables. You address those as hive_metastore.schema.table. This catalog is outside Unity Catalog governance, so privileges and lineage work differently there. If a one-part or two-part name unexpectedly points to old tables, check whether your default catalog is hive_metastore.
Listing what exists at each level
To see what you can address, list objects one level at a time. Each statement works at a different level of the hierarchy.
SHOW CATALOGS;
SHOW SCHEMAS IN dev;
SHOW TABLES IN dev.sales;
DESCRIBE EXTENDED dev.sales.orders;SHOW CATALOGS returns the catalogs you are allowed to see, and SHOW SCHEMAS IN dev does the same for schemas. DESCRIBE EXTENDED shows the table's details, including its type and storage location. Later chapters return to these commands in more depth.
Design guidance for names
A few habits make the namespace easier to live with.
- Use catalogs for large boundaries such as environment or business unit. Use schemas for groups of related tables, such as
salesorfinance. - Keep names short, lowercase, and free of special characters.
- Keep the same schema and table names across catalogs such as
devandprod. Code can then move between environments by changing only the catalog. - Decide early who owns each level. Privileges and ownership follow the hierarchy, and renaming a heavily used catalog later is disruptive.
Exercise
Your notebook runs USE CATALOG dev; and USE SCHEMA sales;. What does each of these resolve to: orders, marketing.leads, and prod.sales.orders? Then explain why a nightly job should avoid the first two forms.
Show answer
orders resolves to dev.sales.orders (current catalog and schema fill in). marketing.leads resolves to dev.marketing.leads, because a two-part name is read as schema.object in the current catalog. prod.sales.orders is fully qualified and is used as written. A nightly job should avoid the first two because its default catalog and schema depend on session or compute settings, so those names can point to different tables, or fail, when the job runs somewhere other than your notebook.
Exercise
A user has SELECT on dev.sales.orders but gets a permission error when querying it. Which two other privileges should you check, and on which objects?
Show answer
Check USE CATALOG on the catalog dev and USE SCHEMA on the schema dev.sales. Querying a table requires access at every level of its name, not just SELECT on the table.