如何解析标识列上的 com.ibm.websphere.ce.cm.DuplicateKeyException

How to resolve com.ibm.websphere.ce.cm.DuplicateKeyException on an identity column

caused by: com.ibm.websphere.ce.cm.DuplicateKeyException: One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "1" constrains table "USER.VLDN_CHK" from having duplicate values for the index key.. SQLCODE=-803, SQLSTATE=23505, DRIVER=3.65.110

有没有办法找到当前序列值,如何将它设置为不同的值?我正在使用 IBM DB2。

table 创建为:

CREATE TABLE "USER"."VLDN_CHK" ( 
  "VLDN_CHK_ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY 
     ( START WITH 180000 INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 
       NO CYCLE CACHE 20 NO ORDER ), 
 "TYPE_NM" VARCHAR(100) NOT NULL, 
 "RSLT_CD" SMALLINT);

检查接下来要分配的值:

SELECT NEXTCACHEFIRSTVALUE
FROM SYSCAT.SEQUENCES
WHERE SEQSCHEMA = 'YOURSCHEMA' AND SEQNAME = 'YOURSEQUENCE'

设置新值

ALTER SEQUENCE YOURSCHEMA.YOURSEQUENCE RESTART WITH <new value> 

标识列也有序列支持。确定下一个身份值

SELECT NEXTCACHEFIRSTVALUE
FROM SYSCAT.COLIDENTATTRIBUTES 
WHERE TABSCHEMA = 'YOURSCHEMA' AND TABNAME = 'YOURTABLE'

(因为 table 中只能有一个标识列)。设置新值

ALTER TABLE YOURSCHEMA.YOURTABLE 
  ALTER COLUMN YOURIDENTITYCOL RESTART WITH <new value>