Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
Databricks SQL
Databricks Runtime
Alters the schema or properties of a table.
Temporary tables support ALTER TABLE ... SET TBLPROPERTIES and ALTER TABLE ... UNSET TBLPROPERTIES in serverless compute, Databricks Runtime 18.2 and above, and Databricks SQL 2026.15 and above. Other ALTER TABLE clauses are not supported on temporary tables and return an error. If the table is cached, the command clears cached data of the table and all its dependents that refer to it. The cache will be lazily filled when the table or the dependents are accessed the next time.
Foreign tables support a limited set of ALTER TABLE operations, including ALTER TABLE SET OWNER, ALTER TABLE RENAME TO, ALTER TABLE SET MANAGED { MOVE | COPY }, and ALTER TABLE SET EXTERNAL. SET MANAGED and SET EXTERNAL require a foreign table federated using Hive metastore and Glue Federation, and SET MANAGED also requires the Delta Lake format. See Foreign tables and Convert a foreign table to an external Unity Catalog table.
Required permissions
If you use Unity Catalog you must have MODIFY permission to:
ALTER COLUMNADD COLUMNDROP COLUMNSET TBLPROPERTIESUNSET TBLPROPERTIES
If you use Unity Catalog you must have MANAGE permission or ownership to:
SET OWNER TOPREDICTIVE OPTIMIZATION
All other operations require ownership of the table, including SET MANAGED and UNSET MANAGED.
SET EXTERNAL and the foreign-table form of SET MANAGED also require CREATE permission on the EXTERNAL LOCATION. For the full prerequisites for each conversion, see Prerequisites and Prerequisites.
Syntax
ALTER TABLE table_name
{ RENAME TO clause |
ADD COLUMN clause |
ALTER COLUMN clause |
DROP COLUMN clause |
RENAME COLUMN clause |
DEFAULT COLLATION clause |
ADD CONSTRAINT clause |
DROP CONSTRAINT clause |
DROP FEATURE clause |
ADD PARTITION clause |
DROP PARTITION clause |
PARTITION SET LOCATION clause |
RENAME PARTITION clause |
RECOVER PARTITIONS clause |
SET { ROW FILTER clause } |
DROP ROW FILTER |
SET TBLPROPERTIES clause |
UNSET TBLPROPERTIES clause |
SET SERDE clause |
SET LOCATION clause |
SET EXTERNAL clause |
SET MANAGED clause |
UNSET MANAGED clause |
SET OWNER TO clause |
SET TAGS clause |
UNSET TAGS clause |
CLUSTER BY clause |
REPLACE PARTITIONED BY WITH CLUSTER BY clause |
PREDICTIVE OPTIMIZATION clause}
Parameters
-
Identifies the table being altered. The name must not include a temporal specification or options specification. If the table cannot be found Azure Databricks raises a TABLE_OR_VIEW_NOT_FOUND error.
RENAME TOto_table_nameRenames the table.
-
Identifies the new table name. The name must not include a temporal specification or options specification.
For Unity Catalog tables, the
to_table_namemust be within the same catalog astable_name. For other tables, theto_table_namemust be within the same schema astable_name.If
to_table_nameis unqualified it is implicitly qualified with the current schema.
> ALTER TABLE student RENAME TO student_info;-
-
Adds one or more columns to the table.
When you add a column to an existing Delta Lake table, you cannot define a
DEFAULTvalue. All columns added to Delta Lake tables are treated asNULLfor existing rows. After adding a column, you can optionally define a default value for new rows usingALTER COLUMN.> DESCRIBE StudentInfo; col_name data_type comment ----------------------- --------- ------- name string NULL rollno int NULL age int NULL > ALTER TABLE StudentInfo ADD columns (LastName string, DOB timestamp); -- After adding new columns to the table > DESCRIBE StudentInfo; col_name data_type comment ----------------------- --------- ------- name string NULL rollno int NULL LastName string NULL DOB timestamp NULL age int NULL -- Optionally set a default value for new rows > ALTER TABLE StudentInfo ALTER COLUMN LastName SET DEFAULT 'unknown';
-
Changes a property or the location of a column.
> DESCRIBE StudentInfo; col_name data_type comment ----------------------- --------- ------- name string NULL rollno int NULL LastName string NULL DOB timestamp NULL age int NULL > ALTER TABLE StudentInfo ALTER COLUMN name COMMENT "new comment"; -- After altering the column > DESCRIBE StudentInfo; col_name data_type comment ----------------------- --------- ----------- name string new comment rollno int NULL LastName string NULL DOB timestamp NULL age int NULLAlter multiple columns in a single statement:
-- Create a table with 3 columns > CREATE TABLE my_table (num INT, str STRING, bool BOOLEAN) TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported') > DESCRIBE TABLE my_table; col_name data_type comment -------- --------- ------- num int null str string null bool boolean null -- Update comments on multiple columns > ALTER TABLE table ALTER COLUMN num COMMENT 'number column', str COMMENT 'string column'; > DESCRIBE TABLE my_table; col_name data_type comment -------- --------- ------------- num int number column str string string column bool boolean null -- Can mix different types of column alter > ALTER TABLE table ALTER COLUMN bool COMMENT 'boolean column', num AFTER bool, str AFTER num, bool SET DEFAULT true; > DESCRIBE TABLE my_table; col_name data_type comment -------- --------- -------------- bool boolean boolean column num int number column str string string column -
Drop one or more columns or fields in a Delta Lake table.
-
Renames a column or field in a Delta Lake table.
> ALTER TABLE StudentInfo RENAME COLUMN name TO FirstName; -- After renaming the column > DESCRIBE StudentInfo; col_name data_type comment ----------------------- --------- ----------- FirstName string new comment rollno int NULL LastName string NULL DOB timestamp NULL age int NULL
-
Adds a check constraint, informational foreign key constraint, or informational primary key constraint to the table.
Foreign keys and primary keys are supported only for tables in Unity Catalog, not the
hive_metastorecatalog. DEFAULT COLLATIONcollation_nameApplies to:
Databricks SQL
Databricks Runtime 16.3 and aboveChanges the default collation of the table for new
STRINGcolumns. Existing columns are not affected by this clause. To change the collation of an existing column, useALTER TABLE ... ALTER COLUMN ... COLLATE collation_name.
-
Drops a primary key, foreign key, or check constraint from the table.
DROP FEATURE feature_name [ TRUNCATE HISTORY ]Applies to:
Databricks Runtime 14.3 LTS and aboveLegacy support for
DROP FEATUREis available starting in Databricks Runtime 14.3 LTS. For documentation of the legacy functionality, see Drop Delta table features (legacy).Applies to:
Databricks SQL
Databricks Runtime 16.3 and aboveAzure Databricks recommends using Databricks Runtime 16.3 and above for all
DROP FEATUREcommands, which replaces the legacy behavior.Removes a feature from a Delta Lake table.
Removing a feature may result in the addition of the
checkpointProtectionwriter feature in the table protocol. For more information, see Drop Delta table features and Protocol versions and table features.feature_nameThe name of a feature in form of a
STRINGliteral or identifier, that must be understood by Azure Databricks and be supported on the table.If the feature is not present in the table Azure Databricks raises DELTA_FEATURE_DROP_FEATURE_NOT_PRESENT.
TRUNCATE HISTORY
Removal of features by truncating history. This requires a two stage process:
The removal of features by truncating history requires a two-step process:
The first invocation clears traces of the feature and informs you of partial success.
Then, wait until the retention period ends before re-executing the statement to complete the removal.
If you initiate the second invocation too early, Azure Databricks raises DELTA_FEATURE_DROP_WAIT_FOR_RETENTION_PERIOD or DELTA_FEATURE_DROP_HISTORICAL_VERSIONS_EXIST.
Truncating the table history limits your ability to perform DESCRIBE HISTORY and execute time travel queries.
-- Drop the "deletion vectors" from a Delta table > ALTER TABLE my_table DROP FEATURE deletionVectors; -- 24 hours later > ALTER TABLE my_table DROP FEATURE deletionVectors TRUNCATE HISTORY;-
Adds one or more partitions to the table.
> SHOW PARTITIONS StudentInfo; partition --------- age=11 age=12 age=15 > ALTER TABLE StudentInfo ADD IF NOT EXISTS PARTITION (age=18); -- After adding a new partition to the table > SHOW PARTITIONS StudentInfo; partition --------- age=11 age=12 age=15 age=18 -- Adding multiple partitions to the table > ALTER TABLE StudentInfo ADD IF NOT EXISTS PARTITION (age=18) PARTITION (age=20); > SHOW PARTITIONS StudentInfo; partition --------- age=11 age=12 age=15 age=18 age=20 -
Drops one or more partitions from the table.
> SHOW PARTITIONS StudentInfo; partition --------- age=11 age=12 age=15 age=18 > ALTER TABLE StudentInfo DROP IF EXISTS PARTITION (age=18); -- After dropping the partition of the table > SHOW PARTITIONS StudentInfo; partition --------- age=11 age=12 age=15 -
Sets the location of a partition.
> ALTER TABLE dbx.tab1 PARTITION (a='1', b='2') SET LOCATION '/path/to/part/ways'; -
Replaces the keys of a partition.
> SHOW PARTITIONS StudentInfo; partition --------- age=10 age=11 age=12 > ALTER TABLE default.StudentInfo PARTITION (age='10') RENAME TO PARTITION (age='15'); -- After renaming Partition > SHOW PARTITIONS StudentInfo; partition --------- age=11 age=12 age=15 -
Instructs Azure Databricks to scan the table's location and add any files to the table which have been added directly to the filesystem.
-
Applies to:
Databricks SQL
Databricks Runtime 12.2 LTS and above
Unity Catalog onlyAdds a row filter function to the table. All subsequent queries to the table receive a subset of the rows where the function evaluates to boolean TRUE. This can be useful for fine-grained access control purposes where the function can inspect the identity or group memberships of the invoking user to determine whether to filter certain rows.
DROP ROW FILTERApplies to:
Unity Catalog onlyDrops the row filter from the table, if any. Future queries will return all rows from the table without any automatic filtering.
-
Sets or resets one or more user defined properties.
> ALTER TABLE dbx.tab1 SET TBLPROPERTIES ('winner' = 'loser'); -
Removes one or more user defined properties.
> ALTER TABLE dbx.tab1 UNSET TBLPROPERTIES ('winner'); SET SERDEApplies to:
Databricks RuntimeSpecifies the serializer/deserializer (SerDe) class used to read and write data in a Hive-format table. You can also configure SerDe properties with
WITH SERDEPROPERTIES.> ALTER TABLE test_tab SET SERDE 'org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe'; > ALTER TABLE dbx.tab1 SET SERDE 'org.apache.hadoop' WITH SERDEPROPERTIES ('k' = 'v', 'kay' = 'vee');SET LOCATIONMoves the location of a table.
SET LOCATION pathLOCATION pathpathmust be aSTRINGliteral. Specifies the new location for the table.Files in the original location will not be moved to the new location.
SET EXTERNAL [ DRY RUN ]Applies to:
Databricks Runtime 17.3 and above
Unity Catalog onlyConverts a foreign table to a Unity Catalog external table, retaining the table history and configurations, including the name, settings, permissions, and views. Supported only on foreign tables federated using Hive metastore and Glue Federation.
Requires
OWNERorMANAGEpermissions on the table andCREATEpermission on theEXTERNAL LOCATION.To roll back the conversion, drop the table. Azure Databricks re-federates it as a foreign table during the next catalog sync.
DRY RUNChecks whether the source table can be converted, without converting it. The command returns
DRY_RUN_SUCCESSif the table can be converted.
For prerequisites and format-specific guidance, see Convert a foreign table to an external Unity Catalog table.
-- Check whether a foreign table can be converted > ALTER TABLE hms_federated_catalog.my_schema.my_table SET EXTERNAL DRY RUN; -- Convert a foreign table to an external table > ALTER TABLE hms_federated_catalog.my_schema.my_table SET EXTERNAL;
SET MANAGEDApplies to:
Databricks Runtime 17.3 LTS and above
Unity Catalog onlyConverts a Unity Catalog external or foreign Delta Lake table to a Unity Catalog managed table. The conversion retains the table name, settings, permissions, views, and history.
External and foreign tables use different forms of the clause, as shown in the following syntax:
SET MANAGED [ TRUNCATE UNIFORM HISTORY ] -- external tables SET MANAGED { MOVE | COPY } -- foreign tablesFor external tables, omit
MOVEandCOPY. If you include either one, Azure Databricks raises DELTA_ALTER_TABLE_SET_MANAGED_UNSUPPORTED_COPY_MOVE_SYNTAX.For foreign tables, specify either
MOVEorCOPY. If you omit both, Azure Databricks raises DELTA_ALTER_TABLE_SET_MANAGED_COPY_OR_MOVE_REQUIRED. To choose between the two forms, see Choose the correct command for your source table.TRUNCATE UNIFORM HISTORYApplies to external tables that have Apache Iceberg reads enabled. If the table has Iceberg reads enabled and you omit this option, Azure Databricks raises DELTA_ALTER_TABLE_SET_MANAGED_DOES_NOT_SUPPORT_UNIFORM_ICEBERG.
TRUNCATE UNIFORM HISTORYtruncates UniForm Iceberg history and doesn't remove Delta Lake history. Truncation causes a short Iceberg read and write downtime.MOVEConverts a foreign table to managed and disables access to the source table in the external catalog. After conversion, access through the external catalog and path-based access fail, so all readers and writers must use the Unity Catalog namespace.
COPYConverts a foreign table to managed without modifying or disabling access to the source table in the external catalog. The conversion copies data into the managed storage location, creating two separate copies of the data. You are responsible for disabling reads and writes to the source table and migrating workloads to the managed table.
For prerequisites, downtime estimates, and troubleshooting, see Convert external or foreign Delta Lake tables to Unity Catalog managed tables.
-- Convert an external table > ALTER TABLE main.default.my_external_table SET MANAGED; -- Convert an external table that has Iceberg reads enabled > ALTER TABLE main.default.my_external_table SET MANAGED TRUNCATE UNIFORM HISTORY; -- Convert a foreign table and disable access to the source table > ALTER TABLE hms_federated_catalog.my_schema.my_table SET MANAGED MOVE;UNSET MANAGEDApplies to:
Databricks Runtime 17.3 LTS and above
Unity Catalog onlyRolls a table converted with
SET MANAGEDback to an external table by updating the table metadata to point to the original external location. Azure Databricks preserves writes made to the managed location after conversion. For a converted external table, you can roll back within 14 days of conversion.UNSET MANAGED [ TRUNCATE UNIFORM HISTORY ]TRUNCATE UNIFORM HISTORYApplies to tables that have Iceberg reads enabled. If the table has Iceberg reads enabled and you omit this option, Azure Databricks raises DELTA_ALTER_TABLE_UNSET_MANAGED_DOES_NOT_SUPPORT_UNIFORM.
Commits made between conversion and rollback support time travel by version, but not by timestamp.
To roll a foreign table converted with
MOVEback to a foreign table, runUNSET MANAGEDand then drop the resulting external table, which re-federates it during the next catalog sync. A foreign table converted withCOPYdoesn't needUNSET MANAGED, because the conversion left the source table unmodified.Warning
If you converted a foreign table with
MOVE, do not drop the managed table before you runUNSET MANAGED. Dropping it first might result in data loss or inconsistencies.For full rollback instructions, see Roll back a managed table conversion.
-- Roll a converted managed table back to an external table > ALTER TABLE main.default.my_managed_table UNSET MANAGED;[ SET ] OWNER TOprincipalTransfers ownership of the table to
principal.Applies to:
Databricks SQL
Databricks Runtime 11.3 LTS and aboveSETis allowed as an optional keyword.Note
Changing the owner is not available on datasets managed by a workspace pipeline.
SET TAGS ( { tag_name = tag_value } [, ...] )Applies to:
Databricks SQL
Databricks Runtime 13.3 LTS and aboveApply tags to the table. You need to have
APPLY TAGpermission to add tags to the table.tag_name
A literal
STRING. Thetag_namemust be unique within the table or column.tag_value
A literal
STRING.
-- Applies three tags to the table named `test`. > ALTER TABLE test SET TAGS ('tag1' = 'val1', 'tag2' = 'val2', 'tag3' = 'val3'); -- Applies three tags to table `main.schema1.test` column `col1`. > ALTER TABLE main.schema1.test ALTER COLUMN col1 SET TAGS ('tag1' = 'val1', 'tag2' = 'val2', 'tag3' = 'val3');UNSET TAGS ( tag_name [, ...] )Applies to:
Databricks SQL
Databricks Runtime 13.3 LTS and aboveRemove tags from the table. You need to have
APPLY TAGpermission to remove tags from the table.tag_name
A literal
STRING. Thetag_namemust be unique within the table or column.
-- Removes three tags from the table named `test`. > ALTER TABLE test UNSET TAGS ('tag1', 'tag2', 'tag3'); -- Removes three tags from table `main.schema1.test` column `col1`. > ALTER TABLE main.schema1.test ALTER COLUMN col1 UNSET TAGS ('tag1', 'tag2', 'tag3');-
Applies to:
Databricks SQL
Databricks Runtime 13.3 LTS and aboveAdds, changes, or drops the clustering strategy for a Delta Lake table.
REPLACE PARTITIONED BY WITH CLUSTER BY [( <clustering_columns> ) | AUTO]Applies to:
Databricks SQL
Databricks Runtime 18.1 and aboveConverts an existing partitioned Delta Lake table to liquid clustering in place, with minimal reader and writer downtime. The
CLUSTER BYclause accepts explicit clustering columns,AUTOto delegate key selection to predictive optimization, or can be omitted to use the existing partition columns.{ ENABLE | DISABLE | INHERIT } PREDICTIVE OPTIMIZATIONApplies to:
Databricks SQL
Databricks Runtime 12.2 LTS and above
Unity Catalog onlyAlters the managed Delta Lake table to the desired predictive optimization setting.
By default, when tables are created, the behavior is to
INHERITfrom the schema.When predictive optimization is explicitly enabled or inherited as enabled OPTIMIZE and VACUUM will be automatically invoked on the table as deemed appropriate by Azure Databricks. For more details see: Predictive optimization for Unity Catalog managed tables.
-- Enables predictive optimization for my_table > ALTER TABLE my_table ENABLE PREDICTIVE OPTIMIZATION;
Additional examples
For Delta Lake add constraints and alter column examples, see
Related articles
- ADD CONSTRAINT clause: Add or drop check constraints, primary keys, and foreign keys.
- ALTER MATERIALIZED VIEW: Syntax for altering materialized views.
- ALTER STREAMING TABLE: Syntax for altering streaming tables.
- ALTER TABLE ... COLUMN clause: Full syntax for ADD, ALTER, DROP, and RENAME COLUMN.
- ALTER TABLE … PARTITION: Full syntax for adding, dropping, and renaming partitions.
- Update table schemas with schema evolution: Rename or change column types in a Delta table.
- Convert external or foreign Delta Lake tables to Unity Catalog managed tables: Prerequisites, downtime estimates, and rollback for
SET MANAGEDandUNSET MANAGED. - Convert a foreign table to an external Unity Catalog table: Prerequisites and format-specific guidance for
SET EXTERNAL.