Sub topic 2
Schemas
This chapter assumes basic SQL, Databricks workspaces, cloud object storage, and users or groups. Unity Catalog uses schemas to organize tables and control access.
Schemas
A schema is a named container inside a catalog. It groups related tables, views, volumes, and functions. Use the three-level name catalog.schema.object to identify an object precisely.
CREATE CATALOG IF NOT EXISTS dev;
CREATE SCHEMA IF NOT EXISTS dev.sales;A schema often represents a subject area, such as sales, finance, or marketing. Keep related objects together so permissions and discovery remain simple.
Tables
A table stores structured rows and columns. Create it inside a schema, then use its fully qualified name in SQL.
CREATE TABLE IF NOT EXISTS dev.sales.orders (
order_id BIGINT,
customer_id BIGINT,
order_ts TIMESTAMP,
amount DECIMAL(10,2)
);
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;You can set the active catalog and schema when working repeatedly in one area:
USE CATALOG dev;
USE SCHEMA sales;
SELECT * FROM orders;Managed and external tables
A managed table has its data location controlled by Unity Catalog. Databricks manages the table metadata and storage lifecycle. An external table keeps its data at a specified cloud path. Unity Catalog manages its metadata, while the data remains at that path.
| Table type | Storage location | Typical use |
|---|---|---|
| Managed | Controlled by Unity Catalog | New data owned by the platform |
| External | Explicit governed cloud path | Existing data or shared storage |
CREATE TABLE dev.sales.raw_orders (
order_id BIGINT,
payload STRING
)
LOCATION 's3://example-bucket/raw/orders';The path is only valid when an authorized external location covers it.
Principals and ownership
A principal is a user, group, or service principal that can receive permissions. Each securable object has an owner. The owner can manage grants and transfer ownership, subject to account rules.
GRANT USE CATALOG ON CATALOG dev TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA dev.sales TO `data-analysts`;
GRANT SELECT ON TABLE dev.sales.orders TO `data-analysts`;USE CATALOG and USE SCHEMA let a group reach the table. SELECT lets it read rows. A schema-level grant can cover current and future tables in that schema.
Exercise
Which privileges does a group need to read dev.sales.orders?
Show answer
It needs USE CATALOG on dev, USE SCHEMA on dev.sales, and SELECT on the table or its schema.