Let’s Get Certified
Module 12 / 21 · Delta Lake and Spark

Tables and views

Compare tables, views, materialized views, and streaming tables. Select a storage and refresh model for each consumer.

The three-level namespace

Catalog Explorer showing the samples.nyctaxi.trips table
In the UI. Catalog Explorer on samples.nyctaxi.trips. The tree on the left reads catalog (samples), schema (nyctaxi), table (trips). The table page has the tabs Overview, Sample Data, Details, Permissions, History, Lineage, Insights and Quality, and the right panel shows the owner, the type (Managed) and the data source (Delta).

Every Unity Catalog object is addressed as catalog.schema.object, for example main.sales.orders. USE CATALOG main; USE SCHEMA sales; sets defaults. Schema and database are synonyms (CREATE SCHEMA = CREATE DATABASE). The legacy per-workspace metastore appears as the catalog hive_metastore.

Each Unity Catalog-enabled workspace has a default catalog (set by an admin). Unqualified names resolve to it unless you run USE CATALOG.

If a statement fails with "the operation attempted to use Hive metastore, which is disabled", no current catalog is set and the workspace has legacy Hive metastore access turned off. Run USE CATALOG main; or fully qualify names.

Managed vs external tables (summary)

ManagedExternal
Data locationUnity Catalog's managed storage for the metastore, catalog or schemaA path you give with LOCATION, inside a registered external location
DROP TABLERemoves the table from the active catalog. Data files are deleted after the configured recovery period (7 days by default). During that period, use UNDROP TABLE.Deletes metadata only; files remain
FormatsDelta (or Iceberg)Delta, Parquet, CSV, JSON, Avro, ORC, text
OptimizationPredictive optimization, automatic featuresYou manage maintenance
RecommendedYes, the defaultWhen other tools must read the same path or data must stay in a given location
CREATE TABLE main.sales.orders (id BIGINT, amount DECIMAL(10,2));            -- managed
CREATE TABLE main.sales.orders_ext (id BIGINT, amount DECIMAL(10,2))
  LOCATION 's3://acme-data/sales/orders';                                  -- external

"Unmanaged table" is the older Hive term for an external table. In Unity Catalog a table's storage is either managed or external.

Conversions between them are covered in Unity Catalog.

Tables over files

An external table can sit directly on files in another format:

CREATE TABLE main.raw.orders_csv (id INT, amount DOUBLE)
USING CSV
OPTIONS (header 'true', delimiter ',')
LOCATION 's3://acme-data/raw/orders/';      -- external, non-Delta: no ACID, no time travel

Foreign tables and catalog types

Besides standard catalogs, Unity Catalog has foreign catalogs (Lakehouse Federation) and shared catalogs (Delta Sharing, Unity Catalog). A foreign catalog (Lakehouse Federation) mirrors a database in an external system such as PostgreSQL or Snowflake. Its tables are foreign tables: read-only from Databricks.

ManagedExternalForeign
Data lives inUC managed storageYour cloud pathThe external system
Read/write from DatabricksRead and writeRead and writeRead only
Automatic optimizationYes (predictive optimization)No, you manage itNo

Comments and generated columns

CREATE TABLE main.sales.tx (
  id BIGINT COMMENT 'Transaction id',
  amount DECIMAL(10,2) COMMENT 'Amount in EUR'
) COMMENT 'Financial transactions by id';
ALTER TABLE main.sales.tx ALTER COLUMN amount COMMENT 'Amount in EUR, tax included';

Comments appear in Catalog Explorer and help discovery and governance.

Generated columns gotcha

Delta generated columns (GENERATED ALWAYS AS (expr)) are always computed on write and stored. There is no VIRTUAL or STORED keyword in Databricks, and the expression must be deterministic, so current_date() cannot be used (an "age" column cannot be generated).

Views

ObjectStores data?Lifetime and scope
View CREATE VIEWNo. Saved query, recomputed at each read.Permanent object in a schema, governed by Unity Catalog
Temporary view CREATE TEMP VIEW, df.createOrReplaceTempViewNoCurrent Spark session only (one notebook). Not registered in the catalog.
Global temporary view CREATE GLOBAL TEMP VIEWNoAll notebooks on the same cluster, until the cluster restarts. Read via global_temp.view_name. Not supported on serverless.
Materialized view CREATE MATERIALIZED VIEWYes, precomputed resultsPermanent. Refreshed on a schedule or by a pipeline, incrementally when possible. Runs on serverless.
Streaming table CREATE STREAMING TABLEYesPermanent Delta table fed by a stream; processes each input row once. Ideal for append-only ingestion.
CREATE OR REPLACE VIEW main.gold.v_revenue AS
SELECT country, SUM(amount) AS revenue FROM main.silver.orders GROUP BY country;

CREATE MATERIALIZED VIEW main.gold.mv_daily_revenue
  SCHEDULE EVERY 1 HOUR
AS SELECT order_date, SUM(amount) AS revenue FROM main.silver.orders GROUP BY order_date;
REFRESH MATERIALIZED VIEW main.gold.mv_daily_revenue;

CREATE OR REFRESH STREAMING TABLE main.bronze.raw_events
  SCHEDULE EVERY 15 MINUTES
AS SELECT * FROM STREAM read_files('/Volumes/main/raw/events/', format => 'json');

Metric views

A metric view defines reusable business metrics (measures and dimensions, for example revenue by region) once, centrally, in Unity Catalog, so every dashboard, Genie space and query uses the same definition.

Choosing a gold-layer object New exam

NeedChoose
Always-current logic, cheap to compute, or a security layer over a tableView
Expensive aggregation or join read often by dashboards; fresh within a refresh intervalMaterialized view
Continuous append of new events with low latency, each record processed onceStreaming table
Full control of writes (MERGE, custom jobs), or results produced by a jobTable
Key distinctions
  • A view stores nothing, so it always shows current data but costs compute at each query.
  • A materialized view stores results and can be stale until refreshed. Updates and deletes in the source are reflected at refresh (it recomputes, incrementally when possible).
  • A streaming table assumes append-only sources. Updates or deletes in the source do not flow through automatically.

Useful inspection commands

SHOW CATALOGS; SHOW SCHEMAS IN main; SHOW TABLES IN main.sales; SHOW VIEWS IN main.gold;
DESCRIBE TABLE EXTENDED main.sales.orders;    -- includes Type: MANAGED / EXTERNAL
SHOW CREATE TABLE main.sales.orders;
COMMENT ON TABLE main.sales.orders IS 'One row per order';
ALTER TABLE main.sales.orders SET TAGS ('domain' = 'sales');

The same commands at schema level, with pattern matching:

DESCRIBE SCHEMA EXTENDED main.todos;      -- schema metadata (owner, location, properties); does NOT list tables
SHOW TABLES IN main.todos;                -- list tables
SHOW TABLE EXTENDED IN main.todos LIKE 'comp*';   -- details for every table matching a pattern
SHOW CREATE TABLE main.todos.completions; -- reveals identity, defaults and constraints

Choose a dashboard object

A dashboard aggregates 18 months of orders and can be an hour behind. Several teams refresh the same report throughout the day. Which object would avoid rerunning the aggregation on every read?

Check your reasoning

Use a materialized view and schedule a refresh compatible with the freshness target. Reads then use the stored result.

Product reference

Databricks tables in the Databricks documentation

Knowledge check

Tables and views quiz

Answer 7 questions. Check each answer for an explanation.