Sub topic 7
Tables
This chapter covers tables in Unity Catalog. It assumes you know basic SQL (CREATE, SELECT, INSERT) and have used a Databricks notebook or the SQL editor. It also assumes you know the catalog and schema levels of the namespace, which earlier chapters cover.
Where tables sit
A table is the third level of the namespace, so its full name is catalog.schema.table. It holds rows and columns and lives inside a schema. Managed versus external storage is a separate topic in the next chapter. Here we focus on creating, writing to, and querying tables.
Creating a table
Create the parent objects first. Then create the table inside the schema.
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)
);Because the statement gives no storage path, this is a managed table. Unity Catalog decides where the files go. The table is now addressed as dev.sales.orders.
You need the right privileges to run these statements. Creating a schema needs CREATE SCHEMA on the catalog. Creating a table needs CREATE TABLE on the schema, plus USE CATALOG and USE SCHEMA on the parents. A later chapter covers privileges in detail.
Writing and querying
Use the fully qualified name to write rows and to read them back.
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;The query returns one row per customer: 25.50 for customer 100 and 80.00 for customer 101.
Using short names
Typing three levels every time is tedious. Set the current catalog and schema, and then the short name resolves.
USE CATALOG dev;
USE SCHEMA sales;
SELECT * FROM orders;Short names resolve against the current catalog and schema of your session. If another notebook has set a different schema, orders may point to a different table or fail. Fully qualified names do not depend on session state, so prefer them in jobs and shared code.
Common errors
| Symptom | Likely cause |
|---|---|
| `TABLE_OR_VIEW_NOT_FOUND` | The name is misspelled, or the current catalog or schema is not the one you expected. |
| Permission denied on a table you can name | You lack `USE CATALOG` or `USE SCHEMA` on a parent, or `SELECT` on the table. |
| `SCHEMA_NOT_FOUND` on create | The schema does not exist yet, so create it first. |
| Table appears in the wrong place | A short name was used and the session pointed at another schema. |
Check your understanding
Exercise
A session has run USE CATALOG dev; and USE SCHEMA sales;. Which two statements refer to the same table, and why might the first one break in a shared job?
1) SELECT * FROM orders;
2) SELECT * FROM dev.sales.orders;
Show answer
Both statements refer to the same table in this session. The first uses a short name that resolves against the session's current catalog and schema. If a different session or job has a different current schema, orders points elsewhere or fails. The second is fully qualified, so it always resolves the same way.
Exercise
A user has SELECT on dev.sales.orders but gets a permission error when querying it. Name two other privileges to check.
Show answer
USE CATALOG on dev and USE SCHEMA on dev.sales. Both are needed on the parent objects before the table is reachable.