0

We are created SQL notebook in Databricks and we are trying to develop onetime script. we have to truncate and load the data every time and the table sequence id generated always start with 1. if we do truncate and load the data. the sequence of id taking last insert value, means not able to restart 1. how do we restart 1 value if we try to insert the data after truncate command.

actual table created,

CREATE TABLE IF NOT EXISTS schema.tablename(
SerialNo BIGINT GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) COMMENT "SerialNo - auto generated sequence id",
adlsSourceMountPath STRING COMMENT "location",
adlsTargetMountPath STRING COMMENT "location",
tableSchemaName STRING COMMENT "tableSchemaName - adls target delta table schema name",
DescriptionDetails STRING COMMENT "DescriptionDetails",
CreateDate DATE COMMENT "CreateDate - generate current date",
Active BOOLEAN COMMENT "Active - check active status of connections"
)USING DELTA
LOCATION "location/path"
COMMENT "descri"

we tried below command but throwing error.

TRUNCAT TABLE TABLENAME RESTART IDENTITY;

please suggest.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
Developer KE
  • 71
  • 1
  • 2
  • 14

1 Answers1

0

There is no such thing as "restart identity" in the truncate command - you can check documentation for it.

If you just have a normal Delta Lake table, then you can either use restore to version 0 or use "create or replace table" as it's described in the following answers.

If you're using Delta Live Tables (looking into tags), then you may need to perform a refresh that should reset identity column as well.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132