Skip to main content

Databricks SQL: A Practical Guide to the Lakehouse Warehouse

One copy of your data for notebooks and dashboards: Delta tables, Unity Catalog, SQL warehouses and the habits that keep cost under control

Updated 10 min readMarkdown
Databricks SQL: A Practical Guide to the Lakehouse Warehouse

The data science team keeps its data as files in cloud storage and works in notebooks. The analysts keep theirs in a warehouse and work in SQL. Every night a job copies data from one side to the other. One morning the churn number in the model and the churn number on the dashboard disagree, and two teams spend the day finding out which copy is stale.

Databricks exists to remove that copy. Its idea, the "lakehouse", is one set of tables in open formats in your own cloud storage, used by notebooks, pipelines and SQL dashboards alike. Databricks SQL is the part that makes those tables feel like a warehouse.

If you are an analyst or engineer meeting Databricks through SQL, this guide covers what you need: how the pieces fit, the SQL that is special to it, and what makes the bill go up.

What Databricks SQL is

Databricks is a data platform that grew out of Apache Spark. It runs on AWS, Azure and Google Cloud. Databricks SQL is its warehouse experience: a SQL editor, dashboards, and compute built for SQL queries.

Four terms carry most of the meaning:

Term Meaning
Delta Lake The default table format. Data is stored as Parquet files, plus a transaction log that records every change
Unity Catalog The governance layer: where tables are registered and permissions are granted
SQL warehouse The compute that runs SQL. It holds no data and can be started and stopped
DBU Databricks Unit, the unit you are billed in for compute

The transaction log is what turns a folder of files into a real table. It gives you ACID transactions (a change happens completely or not at all), UPDATE and DELETE, and a history of versions.

Tables have three-part names: catalog.schema.table, for example main.sales.orders.

Why teams choose it

  • One copy of the data. SQL users, Python notebooks, streaming jobs and machine learning all read the same Delta tables.
  • Open formats in your own storage. The files sit in your bucket as Parquet. Delta Lake is open source, and other engines can read it.
  • Strong for data engineering and ML. Pipelines, notebooks, model training and serving live on the same platform as the warehouse.
  • One permission model. Unity Catalog governs tables, files, models and dashboards together.
  • History built in. Every table keeps versions you can query or restore.

Where Databricks SQL fits, and where it does not

A strong choice for:

  • Teams that do data science or heavy data engineering as well as reporting
  • Large volumes of raw and semi-structured data that are refined in stages
  • Companies that want their data in open formats in their own cloud account
  • Streaming and batch pipelines feeding the same tables

Look elsewhere when:

  • You only need a SQL warehouse. Snowflake and BigQuery have fewer concepts to learn if nobody will touch a notebook or a pipeline.
  • You need an application database. Delta tables are built for analysis, not for thousands of small transactions per second. Use PostgreSQL or MySQL for that.
  • Your data is small. A few gigabytes are served well by PostgreSQL, or DuckDB on a laptop.
  • Queries are rare and the files already sit in S3. Amazon Athena has nothing to start or stop.
  • Nobody will own the platform. Workspaces, catalogs, storage credentials and cluster policies need someone who understands them.

Using it the right way

Create tables with clustering, not deep partitions

CREATE TABLE main.sales.orders (
  order_id    BIGINT NOT NULL,
  customer_id BIGINT,
  status      STRING,
  total       DECIMAL(12,2),
  created_at  TIMESTAMP
)
CLUSTER BY (created_at);

CLUSTER BY turns on liquid clustering, available on current Databricks runtimes. It keeps rows with nearby values together so queries can skip files, and you can change the clustering columns later without rewriting the table yourself. It replaces the older habit of partitioning by date and by several other columns, which often produced thousands of tiny files.

A table created without a USING clause is a Delta table.

Load files so that reruns are safe

COPY INTO main.sales.orders
FROM '/Volumes/main/sales/landing/orders/'
FILEFORMAT = PARQUET;

COPY INTO remembers which files it has loaded. Run it again and only new files are added. A volume is a Unity Catalog object that points at a folder of files in cloud storage.

Upsert with MERGE

MERGE INTO main.sales.orders AS t
USING main.sales.orders_updates AS s
  ON t.order_id = s.order_id
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;

SET * and INSERT * copy every column with a matching name. MERGE is the standard way to apply a batch of changes, and because of the transaction log, readers see either the old version or the new one, never half of each.

Use the history

-- What happened to this table, and when
DESCRIBE HISTORY main.sales.orders;

-- The table as it was at version 12, or at a time
SELECT * FROM main.sales.orders VERSION AS OF 12;
SELECT * FROM main.sales.orders TIMESTAMP AS OF '2026-03-01 09:00:00';

-- Undo a bad change
RESTORE TABLE main.sales.orders TO VERSION AS OF 12;

This is the fastest recovery from a wrong DELETE or a broken pipeline run.

Keep files tidy

Changes to a Delta table write new files and mark old ones as no longer current. Two commands look after that:

OPTIMIZE main.sales.orders;
VACUUM main.sales.orders;

OPTIMIZE merges small files into larger ones and applies clustering. VACUUM deletes files that no version inside the retention period still needs; the default keeps seven days. On managed Unity Catalog tables, a feature called predictive optimization can run both for you.

Be careful with VACUUM: once old files are gone, you cannot time travel to versions that needed them.

Grant access through Unity Catalog

GRANT USE CATALOG ON CATALOG main TO `analysts`;
GRANT USE SCHEMA ON SCHEMA main.sales TO `analysts`;
GRANT SELECT ON SCHEMA main.sales TO `analysts`;

A user needs all three levels: use of the catalog, use of the schema, and SELECT. Granting SELECT on the schema covers the tables in it, including ones created later. Grant to groups, not to individuals.

Know what constraints do

NOT NULL and CHECK constraints are enforced on Delta tables. PRIMARY KEY and FOREIGN KEY in Unity Catalog are informational: they document the model and help tools, but duplicates are not rejected. Deduplicate in your pipeline, usually with MERGE.

How the pricing shapes your habits

You pay for compute in DBUs and for storage to your cloud provider, since the files are in your own account.

SQL warehouses come in three types. With serverless warehouses, the machines are run by Databricks and are included in the DBU rate; they start in seconds. With pro and classic warehouses, the virtual machines run in your cloud account, so you pay Databricks for DBUs and your cloud provider for the machines, and they take minutes to start.

A warehouse uses DBUs for every hour it is running, at a rate set by its size, whether or not queries are arriving. That leads to four habits:

  • Set auto stop short. Serverless warehouses restart quickly, so a few minutes of idle time before stopping is comfortable. Slow-starting classic warehouses tempt people to leave them on, which is where money leaks.
  • Start small. Each size up roughly doubles the rate. Go up when single queries are slow.
  • Scale out for crowds. If queries queue because many people are working, raise the maximum number of clusters, not the size.
  • Keep BI off general-purpose clusters. SQL warehouses are built and priced for SQL. A notebook cluster left on for a dashboard usually costs more for a worse result.

To see where DBUs went, query the billing system table (an administrator must enable access to system tables):

SELECT usage_date, sku_name, SUM(usage_quantity) AS dbus
FROM system.billing.usage
WHERE usage_date >= current_date() - INTERVAL 30 DAYS
GROUP BY usage_date, sku_name
ORDER BY usage_date DESC, dbus DESC;

Storage has its own trap: every UPDATE and DELETE leaves old files behind until VACUUM removes them. A heavily rewritten table can hold several times its visible size.

Common mistakes

  • A warehouse with auto stop turned off. It bills all night and all weekend.
  • Partitioning by a high-cardinality column. A partition per customer or per hour makes millions of small files. Prefer liquid clustering.
  • Never running OPTIMIZE on a table fed by many small writes. Reads slow down as the file count grows.
  • Lowering VACUUM retention to save storage. It can break time travel and running queries that still need the old files.
  • Assuming primary keys prevent duplicates. They do not.
  • Granting to individual users. Access becomes impossible to review. Use groups.
  • Long-lived personal access tokens in shared tools. A token carries all of that person's permissions. For automation, use a service principal with only the access it needs, and give tokens an expiry.
  • SELECT * on wide tables. Parquet is columnar, so naming columns reads less.

Quick reference

Task Command
List catalogs SHOW CATALOGS;
List schemas SHOW SCHEMAS IN main;
List tables SHOW TABLES IN main.sales;
Describe a table DESCRIBE TABLE EXTENDED main.sales.orders;
Size and file count DESCRIBE DETAIL main.sales.orders;
Change history DESCRIBE HISTORY main.sales.orders;
Table definition SHOW CREATE TABLE main.sales.orders;
Who can do what SHOW GRANTS ON SCHEMA main.sales;
Refresh statistics ANALYZE TABLE main.sales.orders COMPUTE STATISTICS;
Set the default location USE CATALOG main; USE SCHEMA sales;

The lakehouse gives you one copy of the truth. Keep it healthy with clustered tables, MERGE for changes, regular file maintenance and warehouses that switch themselves off.

Exploring Databricks with CreamDB

Databricks has a full SQL editor of its own. If you want your Databricks tables beside your other databases, CreamDB connects to a SQL warehouse from a browser tab, with nothing to install.

  • Connect with the three values on the warehouse's "Connection details" tab: the server hostname, the HTTP path and a personal access token. You can also set a default catalog and schema. The token is stored encrypted.
  • Browse catalogs, schemas, tables, views and columns in a tree.
  • Write SQL in an editor with autocomplete, formatting and history, and export results to CSV, JSON or Excel.
  • Ask in plain English, for example "orders per week by status this year", and get the SQL, a result table and a chart.

The assistant only reads on its own. Any change waits as an approval card that you answer, and read-only mode on the server blocks writes.

Two practical notes. Opening the connection starts the warehouse if it is stopped, so use one with a short auto stop. And the workspace must accept connections from the internet; a workspace locked to private networking cannot be reached. It is free to start.

About the author

  • CreamDB is a web-based database explorer with an AI assistant. Connect your databases, ask questions in plain English and get answers, tables and charts from any browser. Product news and tips here.

No comments yet. Be the first to comment.