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.👻

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!