cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Can we modify the constraint of a primary key in an existed table?

jeremy98
New Contributor III

 

Hello Community,

Is it possible to modify the schema of an existing table that currently has an ID column without any constraints? I would like to update the schema to make the ID column a primary key with auto-increment starting by the maximum id already present in the existed table. Is recreating the schema the only way to achieve this?

1 ACCEPTED SOLUTION

Accepted Solutions

PiotrMi
New Contributor II

Hey @jeremy98 

Based on some old article it looks it cannot be done:

There are a few caveats you should keep in mind when adopting this new feature. Identity columns cannot be added to existing tables; the tables will need to be recreated with the new identity column added. To do this, simply create a new table DDL with the identity column, and insert the existing columns into the new table, and surrogate keys will be generated for the new table.

I think recreate and copy data will be the ea

View solution in original post

1 REPLY 1

PiotrMi
New Contributor II

Hey @jeremy98 

Based on some old article it looks it cannot be done:

There are a few caveats you should keep in mind when adopting this new feature. Identity columns cannot be added to existing tables; the tables will need to be recreated with the new identity column added. To do this, simply create a new table DDL with the identity column, and insert the existing columns into the new table, and surrogate keys will be generated for the new table.

I think recreate and copy data will be the ea

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