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: 

Issue with identity key column in databricks?

ramankr48
Contributor II

For the identity key I've used both

GENERATED ALWAYS AS IDENTITY(start with 1 increment by 1) and

GENERATED BY DEFAULT AS IDENTITY(start with 1 increment by 1)

but in both cases, if I'm running my script once then it is fine (identity key is working as it should be) but when I'm running it second time the old one is getting removed and new identity key is being generated.

ex: let's suppose I'm inserting 10 rows in the table and running the script then identity key is being generated from 1 to 10. but second time when I'm running the script identity is generating from 11 to 20.

that's the issue.

I'm also trying to truncate the table but not fruitfull. Using DBR Version 10.4

2 REPLIES 2

elgeo
Valued Contributor II

Can you share the script you are running?

lizou
Contributor II

yes, by default option allow duplicated values per design.

I will avoid this option and use only use GENERATED ALWAYS AS IDENTITY 

Using BY DEFAULT option is worse than not using it at all

in BY Default option,

If I forget to set starting value, the ID will be generated from

a lower value and will grow and overlap existing values.👻

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