Sub topic 8
Managed and external tables
This chapter assumes you can write basic SQL, know that a table in Databricks is a set of files in cloud object storage, and have already seen the three-level name catalog.schema.table. It covers what separates a managed table from an external one, how to create each, how to tell them apart, and the errors people hit most often.
Two kinds of table, one difference
Every table in Unity Catalog has a name, a schema, and data files in cloud storage. The two table types differ in one respect: who owns the files.
- A managed table is a table whose data files Unity Catalog stores and manages. You do not choose the path. Unity Catalog places the files in the managed storage location of the table's schema, catalog, or metastore.
- An external table is a table whose data files live at a path you choose. Unity Catalog registers the table and controls access to it, but it does not own the files.
The difference shows up when you drop the table. Dropping a managed table deletes its data after a retention period. Dropping an external table removes only the table definition from the metastore, and the files stay where they are.
| Question | Managed table | External table |
|---|---|---|
| Who picks the storage path? | Unity Catalog | You, with `LOCATION` |
| Where is the data? | Managed storage of the schema, catalog, or metastore | Path covered by an external location |
| What does `DROP TABLE` do to the files? | Deletes them after a retention period | Leaves them untouched |
| Does the path need an external location? | No | Yes |
| Typical use | Default for new data | Data that other systems also read or write |
Creating a managed table
If you leave out LOCATION, you get a managed table. This is the same example used earlier in the tutorial.
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)
);The statement never mentions a path. Unity Catalog works out where the files go by looking for the nearest managed storage location, searching in this order:
- The schema's managed location, if one was set.
- The catalog's managed location, if one was set.
- The metastore's managed location.
The table's files are written to the first of these that exists. This lookup is why a catalog-per-environment layout can keep each environment's data in a separate storage account. You set the managed location once on the catalog, and every managed table inside it follows.
You then write and read the table as usual.
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;Managed tables use Delta Lake by default, so you get transactions, time travel, and the table maintenance features that Databricks can run for you.
Creating an external table
An external table needs an explicit LOCATION.
CREATE TABLE dev.sales.raw_orders (
order_id BIGINT,
payload STRING
)
LOCATION 's3://example-bucket/raw/orders';The bucket name here is a placeholder. The statement succeeds only if two things are true:
- The path falls under an external location, which is a Unity Catalog object that pairs a cloud storage path with a storage credential.
- You hold the privilege to create external tables on that external location (
CREATE EXTERNAL TABLE), in addition to the usualCREATE TABLEprivilege on the schema.
If the path is not covered by any external location, the statement fails. The same happens if you have no privilege on the location that covers it. The next chapters on storage credentials explain how those objects are set up. For now, remember that an external table is a table plus a path that Unity Catalog has been told it may use.
Seeing which kind you have
DESCRIBE EXTENDED shows the table type and the storage path.
SHOW CATALOGS;
SHOW SCHEMAS IN dev;
SHOW TABLES IN dev.sales;
DESCRIBE EXTENDED dev.sales.orders;In the detailed table information, look for these rows:
TypeisMANAGEDorEXTERNAL.Locationis the path of the data files.
You can also query the catalog's information_schema, which lists tables and their types.
SELECT table_schema, table_name, table_type
FROM dev.information_schema.tables
WHERE table_schema = 'sales';In that output, table_type is MANAGED or EXTERNAL for tables. Views appear with a different value, so you can filter on this column when you audit a schema.
What happens on DROP
The drop behavior is the most important practical difference, so it is worth walking through.
For a managed table, the deletion is not immediate. Unity Catalog keeps the dropped table recoverable for a limited period, which Databricks documents as seven days at the time of writing. During that window you can restore it with UNDROP TABLE. Check the current documentation for the exact period and for the cases where UNDROP is not available. Do not treat it as a backup strategy.
For an external table, dropping is safe for the data but not for the metadata. After the drop you lose the table's grants, comments, and any other metadata stored in the metastore. If you re-create the table over the same path, you must grant privileges again.
Choosing between them
Start with managed tables unless you have a specific reason not to. Databricks manages the file layout, applies maintenance, and can optimize storage for you. You also avoid creating storage credentials and external locations for every dataset.
Choose an external table when one of these applies:
- Other tools outside Databricks must read or write the same files directly, and you cannot route them through Databricks.
- The data already exists at a path and you want to register it without copying it.
- Policy requires that the files outlive the table definition, so a mistaken
DROP TABLEcannot remove data. - You need a specific storage path that does not match any managed storage location.
Some reasons people give for choosing external tables are weaker than they sound. "I want to control the path" is rarely a requirement, since managed locations on a catalog or schema give you control at a coarser level. "I want to keep my data safe from drops" is better handled with privileges, because only the owner or a user with sufficient rights can drop a table.
Common errors
The path is not covered by an external location. The CREATE TABLE ... LOCATION statement fails with a message about missing permission or an unknown location. Check the external locations you can see and confirm that your path is inside one of them and that you hold the needed privileges on it.
Missing CREATE EXTERNAL TABLE. Having CREATE TABLE on the schema is not enough for external tables. The privilege on the external location is a separate requirement.
Expecting a managed table to survive a drop. After the retention period, the files are gone. If another team reads those files directly from storage, their jobs fail. This is one more reason that managed table files should be accessed only through Unity Catalog.
Reading managed files directly from storage. The managed storage path is an implementation detail. Paths can change shape, and direct access bypasses Unity Catalog's permissions. Query the table by name instead.
Assuming a drop of an external table cleans up storage. It does not. If you want the files gone, you must delete them in the cloud storage yourself, and you should confirm that no other table or process uses them first.
Exercise
A teammate runs DROP TABLE on dev.sales.raworders, which was created with a LOCATION clause. A week later someone drops dev.sales.orders, which was created without one. Describe what happens to the data files in each case, and name one thing the owner of raworders still has to redo if they re-create it.
Show answer
Dropping raworders (external) removes only the metastore entry. The files at the registered path stay in cloud storage. Dropping orders (managed) removes the entry, and its files are deleted after the retention period, during which it can be restored. If raworders is re-created over the same path, the owner must grant privileges again, because grants and comments were stored in the metastore and are lost with the drop.
Exercise
You run CREATE TABLE dev.sales.events (id BIGINT) LOCATION 's3://example-bucket/events'; and it fails. Give two possible causes and one query or command you would use to investigate.
Show answer
Possible causes: the path is not covered by any external location, or you lack the privilege to create external tables on the external location that covers it (CREATE EXTERNAL TABLE), or lack CREATE TABLE on the schema. To investigate, list the external locations you can see and check the grants on the one that should cover the path, for example with SHOW EXTERNAL LOCATIONS and SHOW GRANTS ON EXTERNAL LOCATION followed by the location name.