Sub topic 7
Addressing data with catalog.schema.table
This chapter assumes you know basic SQL (SELECT, WHERE, JOIN, GROUP BY) and have seen a Databricks workspace. It also assumes you know what a catalog, a schema, and a table are in general terms. You will learn how Unity Catalog names data and how to use those names in the SQL editor.
The three-level namespace
Unity Catalog organizes data in three levels. A full table name has three parts separated by dots.
| Level | What it holds | Example |
|---|---|---|
| Catalog | A top-level container, often one per environment or team | `samples` |
| Schema | A group of tables, views, and functions inside a catalog | `nyctaxi` |
| Table | The data itself | `trips` |
Together they form samples.nyctaxi.trips. This is the fully qualified name. It points to one object no matter which warehouse runs the query or which user runs it.
Exploring what you can see
Start by listing the catalogs your account can access. You only see objects you have permission to see.
SHOW CATALOGS;
SELECT * FROM samples.nyctaxi.trips LIMIT 10;The first statement returns one row per catalog. The second reads ten rows from the sample table by using its full name. You can browse the same hierarchy in the schema browser beside the editor, where clicking a table name inserts it into your query.
You can also list the next level down with SHOW SCHEMAS IN samples; and SHOW TABLES IN samples.nyctaxi;.
Setting a default catalog and schema
Typing three parts every time gets tedious. You can set defaults for the session, and then shorter names resolve against them.
USE CATALOG samples;
USE SCHEMA nyctaxi;
SELECT COUNT(*) FROM trips;Here trips is a partially qualified name. It resolves to samples.nyctaxi.trips because of the two USE statements. You can also write nyctaxi.trips after only USE CATALOG samples;.
The editor also lets you pick a catalog and schema from a selector above the query. This sets the same defaults for that editor tab.
Common errors
TABLE_OR_VIEW_NOT_FOUND: The name is misspelled, the default catalog or schema is not what you think, or you lack permission. RunSELECT current_catalog(), current_schema();to see your current defaults.- Wrong catalog selected: A table with the same schema and table name can exist in several catalogs, such as
devandprod. A short name may quietly read the wrong one. - Names with special characters: A name containing hyphens, spaces, or other special characters must be wrapped in backticks, for example `
my-catalog.sales.orders`. - Permission errors: Seeing a catalog in
SHOW CATALOGSdoes not mean you can read every table in it. Access is granted at each level, and you need privileges on the table itself and usage access on its parent catalog and schema.
Why this matters for warehouses
A SQL warehouse provides compute only. It holds no data of its own. The same query text returns the same result on any warehouse, because the three-level name points to data in Unity Catalog, not to the warehouse. This is why you can switch warehouses to change speed or cost without rewriting queries.
Exercise
You run SELECT * FROM orders; and get TABLEORVIEWNOTFOUND, although a colleague says the table is sales.public.orders. Give two ways to fix the query.
Show answer
Use the full name: SELECT * FROM sales.public.orders;. Or set defaults first with USE CATALOG sales; and USE SCHEMA public;, then run the original short-name query. You can also pick the catalog and schema in the editor selector. If the error remains, check that you have privileges on the table.