---
title: Work with external tables
description: Unity Catalog external tables store data in cloud object storage you manage, with Unity Catalog governing access but not the data lifecycle. Use for existing data or formats incompatible with managed tables.
canonical_url: https://docs.databricks.com/aws/en/tables/external
---

# Work with external tables

In Unity Catalog, an external table stores its data files in cloud object storage within your cloud tenant. Unity Catalog continues to manage the table's metadata, ensuring full data governance across all queries. However, it doesn't manage the data's lifecycle, optimization, storage location, or layout.

When you define a Unity Catalog external table, you must specify a storage location. This location is an [external location](https://docs.databricks.com/aws/en/connect/unity-catalog/cloud-storage/index.md#external-locations) registered in Unity Catalog. When you drop an external table, Unity Catalog removes the table metadata but does not delete the underlying data files.

This page focuses on Unity Catalog external tables. External tables in the legacy Hive metastore have different behaviors. See [Database objects in the legacy Hive metastore](https://docs.databricks.com/aws/en/database-objects/hive-metastore.md).

## When to use external tables

Databricks recommends using external tables for the following use cases:

* You need to register a table backed by existing data that isn't compatible with Unity Catalog managed tables, such as JSON or Avro. See [File formats for external tables](https://docs.databricks.com/aws/en/tables/external.md#formats).
* You require direct access to the data from non-Databricks clients that don't support other external access patterns. Unity Catalog privileges are not enforced when users access data files from external systems. See [Access Databricks data using external systems](https://docs.databricks.com/aws/en/external-access/index.md).

In most cases, Databricks recommends using [Unity Catalog managed tables](https://docs.databricks.com/aws/en/tables/managed.md) to take advantage of automatic table optimization, faster query performance, and reduced costs. To migrate external tables to managed tables, see [Convert external or foreign Delta Lake tables to Unity Catalog managed tables](https://docs.databricks.com/aws/en/tables/convert-to-managed.md).

> [!IMPORTANT]
>
> If you update external table metadata using a non-Databricks client or using path-based access from within Databricks, that metadata does not automatically sync state with Unity Catalog. Databricks recommends against such metadata updates, but if you do perform one, you must run `MSCK REPAIR TABLE <table-name> SYNC METADATA` to bring the schema in Unity Catalog up to date. See [REPAIR TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-repair-table.md).

## <a id="formats" />File formats for external tables

External tables can use the following file formats:

* DELTA
* CSV
* JSON
* AVRO
* PARQUET
* ORC
* TEXT

## <a id="create-external-table" />Create an external table

You can create external tables using SQL commands or DataFrame write operations.

### <a id="prerequisites" />Prerequisites

Before you create an external table, you must first configure an external location that grants access to your cloud storage.

Databricks recommends using the automated setup to create external locations. This approach automatically configures both the storage credential and external location. For detailed instructions, see the [automated setup](https://docs.databricks.com/aws/en/connect/unity-catalog/cloud-storage/s3/automatedsetups3.md).

To create an external table, you must meet the following permission requirements:

* The `CREATE EXTERNAL TABLE` privilege on an external location that grants access to the `LOCATION` accessed by the external table.
* The `USE CATALOG` permission on the table's parent catalog.
* The `USE SCHEMA` permission on the table's parent schema.
* The `CREATE TABLE` permission on the table's parent schema.

> [!NOTE]
>
> When an S3 external location is associated with multiple metastores, avoid granting write access to tables that use that S3 location because writes from different metastores to the same external table can cause consistency issues. However, reading from the same S3 external location across multiple metastores is safe.

### <a id="sql-examples" />Examples

Use one of the following examples in a notebook or the SQL query editor to create an external table.

In the following examples, replace the placeholder values:

* `<catalog>`: The name of the catalog that will contain the table.
* `<schema>`: The name of the schema that will contain the table.
* `<table-name>`: A name for the table.
* `<column-name>` and `<data-type>`: The name and data type for each column.
* `<bucket-path>`: The path to the cloud storage bucket where the table will be created.
* `<table-directory>`: A directory where the table will be created. Use a unique directory for each table.
* `<source-table>`: A table to use as the data source when creating a table from query results.

#### SQL

Table paths must contain only standard ASCII characters (letters `A–Z`, `a–z`, digits `0–9`, and common symbols like `/`, `_`, `-`).

To create an external table in S3 with a defined schema, run the following:

```sql
CREATE TABLE <catalog>.<schema>.<table-name>
(
  <column-name> <data-type>
)
LOCATION 's3://<bucket-path>/<table-directory>';
```

To create an external table in S3 from query results, run the following:

```sql
CREATE TABLE <catalog>.<schema>.<table-name>
LOCATION 's3://<bucket-path>/<table-directory>'
AS SELECT * FROM <source-table>;
```

#### Python

To create an external table in S3 with a defined schema, run the following:

```python
from pyspark.sql.types import StructType, StructField, StringType

schema = StructType([StructField("<column-name>", <data-type>())])

spark.createDataFrame([], schema).write \
  .option("path", "s3://<bucket-path>/<table-directory>") \
  .saveAsTable("<catalog>.<schema>.<table-name>")
```

To create an external table in S3 from a DataFrame, run the following:

```python
df.write \
  .option("path", "s3://<bucket-path>/<table-directory>") \
  .saveAsTable("<catalog>.<schema>.<table-name>")
```

For more information about table creation parameters, see [CREATE TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-table.md).

The following SQL syntax options work with DataFrame operations:

* [CREATE TABLE \[USING\]](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-table-using.md)
* [CREATE TABLE LIKE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-table-like.md)

## <a id="drop-external-table" />Drop an external table

To drop a table you must be its owner or have the `MANAGE` privilege on the table. To drop an external table, run the following command:

### SQL

```sql
DROP TABLE IF EXISTS catalog_name.schema_name.table_name;
```

### Python

```python
spark.sql("DROP TABLE IF EXISTS catalog_name.schema_name.table_name")
```

Alternatively, in Databricks Runtime 18.2 and above, use `spark.catalog.dropTable()`:

```python
spark.catalog.dropTable("catalog_name.schema_name.table_name", ifExists=True)
```

Unity Catalog does not delete the underlying data in cloud storage when you drop an external table. You must directly delete the underlying data files if you need to remove data associated with the table.

## <a id="example-notebook-external-table" />Example notebook: Create external tables

You can use the following example notebook to create a catalog, schema, and external table, and to manage permissions on them.

For a simplified setup experience, Databricks recommends using the [automated setup](https://docs.databricks.com/aws/en/connect/unity-catalog/cloud-storage/s3/automatedsetups3.md) to create the external location before running this notebook.

#### Create and manage an external table in Unity Catalog notebook

[Get notebook](https://docs.databricks.com/notebooks/source/unity-catalog-external-table-example-aws.html)
