フィルターのクリア

Primary key issue in insert a table into SQlServer database

2 ビュー (過去 30 日間)
JFz
JFz 2017 年 3 月 15 日
コメント済み: MEP 2022 年 1 月 26 日
Don't know why but keep getting this error: java.sql.BatchUpdateException: Violation of PRIMARY KEY constraint 'PK__ANLS_SCO__DDF02C0878DED853'. Cannot insert duplicate key in object '********'. The duplicate key value is (Mar 13 2017 12:00AM, Jun 1 2017 12:00AM).
I have no clue why this is happening because yesterday I used insert and fastinsert on another table without any problem.
Thanks for any help!

採用された回答

Guillaume
Guillaume 2017 年 3 月 15 日
編集済み: Guillaume 2017 年 3 月 15 日
I'm not sure what is not clear about the error. As it says, you're trying to add a row whose value for the primary key already exists in the table and you have a constraint on the table that the primary key must be unique.
In other words, you already have a row whose primary key value is (Mar 13 2017 12:00AM, Jun 1 2017 12:00AM). Your table schema forbids you to add another row with that same key.
Two possible solutions:
  • remove the constraint on the primary key. Most likely a bad idea.
  • do not try to add duplicate rows. Instead you can UPDATE the rows in question.
  1 件のコメント
MEP
MEP 2022 年 1 月 26 日
Yes, but how can I set the clause if I want to update the row without overwriting the primary key?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by