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: 

Databricks JDBC write to table with PK column, error, key not found.

JamesY
New Contributor III

Hello, I am trying to write data to table, it works find before, but after I recreated the table with one column as PK, there is an error.

Unable to write into the A_Table table....key not found: id

 What is the correct way of doing this?
PK column:   [ID] [bigint] IDENTITY(1,1) PRIMARY KEY NOT NULL

1 ACCEPTED SOLUTION

Accepted Solutions

Kaniz_Fatma
Community Manager
Community Manager

Hi @JamesYIf you’re using Databricks with SQL Server, you can use the OUTPUT clause to retrieve the primary key value after an INSERT query.

CREATE TABLE A_Table (
    ID BIGINT IDENTITY PRIMARY KEY,
    -- Other columns...
);

INSERT INTO A_Table OUTPUT inserted.ID VALUES ('new item');

The OUTPUT clause allows you to capture the inserted primary key value.

View solution in original post

1 REPLY 1

Kaniz_Fatma
Community Manager
Community Manager

Hi @JamesYIf you’re using Databricks with SQL Server, you can use the OUTPUT clause to retrieve the primary key value after an INSERT query.

CREATE TABLE A_Table (
    ID BIGINT IDENTITY PRIMARY KEY,
    -- Other columns...
);

INSERT INTO A_Table OUTPUT inserted.ID VALUES ('new item');

The OUTPUT clause allows you to capture the inserted primary key value.

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