cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Alter table

Phani1
Valued Contributor II

Hi Team, Could you please suggest, Do we have an alternate approach to alter the table instead of creating a new table and copying the data as part of the deployment.

1 REPLY 1

Kaniz_Fatma
Community Manager
Community Manager

Hi @Phani1, When deploying changes to a table in Azure Databricks, you can use an alternate approach to alter the table without creating a new one and copying data. Here are some options:

ALTER TABLE Statement:

  • The ALTER TABLE statement allows you to modify the schema or properties of an existing table. You can use it to:
    • Rename the table within the same schema.
    • Add new columns to the table.
    • Alter properties or the location of existing columns.
    • Drop columns from the table.
    • Rename columns.
    • Add constraints (check, foreign key, or primary key).
    • And more!

Delta Lake Specific:

  • If youโ€™re using Delta Lake, consider using the REPLACE clause when creating a table. This preserves the table history and is recommended over dropping and re-creating tables.
  • Delta Lake also supports type changes and renaming columns using the REWRITE feature.

Renaming Existing Tables:

  • If you want to keep the existing data but rename the table, you can follow these steps:
    1. Create a new table (e.g., NewTable) with the desired schema.
    2. Copy the relevant data from the old table (e.g., OldTable) to the new table.
    3. Rename the old table (e.g., OldTable_History).
    4. Finally, rename the new table to the original table name (e.g., OldTable).

Adjust the table names and conditions according to your use case. Choose the approach that best fits your requirements and existing data. Happy deploying! ๐Ÿš€๐Ÿ”

For more detailed syntax and examples, refer to the official documentation.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group