473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

SQLSTATE: 23505 UDB DB2 8.1.5

Given the DDL:

CREATE TABLE JOHNTEST.TASK_LIST (
TASK BIGINT GENERATED BY DEFAULT AS IDENTITY
(START WITH 1, INCREMENT BY 1, CACHE 20) NOT NULL,
PRI CHAR(1) NOT NULL,
SUBP DECIMAL(7,4),
ATO VARCHAR(25),
REASON VARCHAR(25),
DESCRIPTION VARCHAR(2000),
FILES varchar(500),
TOLD CHAR(1),
last_changed timestamp not null default current_timestamp
)

CREATE INDEX JOHNTEST.tl_primary
ON JOHNTEST.TASK_LIST(TASK)

Alter TABLE JOHNTEST.TASK_LIST add constraint primary
PRIMARY KEY(TASK)

Why does the sql statement:

INSERT INTO JOHNTEST.TASK_LIST(TASK, "ATO", "PRI", "SUBP", "DESCRIPTION")
VALUES(default,'Bob', 'z', 999.999, 'testing')

caues the error message:

DB2 SQL error: SQLCODE: -803, SQLSTATE: 23505, SQLERRMC:
1;JOHNTEST.TASK_LIST
Message: 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 "JOHNTEST.TASK_LIST" from having duplicate rows for
those columns. 

I thought my primary key would be generated every time, uniquely
Nov 12 '05 #1
4 46633
Bob Stearns wrote:
....
I thought my primary key would be generated every time, uniquely


I cannot recreate this on my V8.2 FP9 database; how did you populated this
table? Only by using quoted INSERT or did you use LOAD?

Jan M. Nelken
Nov 12 '05 #2
Jan M. Nelken wrote:
Bob Stearns wrote:
...
I thought my primary key would be generated every time, uniquely

I cannot recreate this on my V8.2 FP9 database; how did you populated
this table? Only by using quoted INSERT or did you use LOAD?

Jan M. Nelken


Good guess. My colleague was using a set of insert statements generated
by an export, so that the rows had the task value. All I had to do was
set START WITH greater than the largest inserted row.
Nov 12 '05 #3
Bob Stearns wrote:
Given the DDL:

CREATE TABLE JOHNTEST.TASK_LIST (
TASK BIGINT GENERATED BY DEFAULT AS IDENTITY
(START WITH 1, INCREMENT BY 1, CACHE 20) NOT NULL,
PRI CHAR(1) NOT NULL,
SUBP DECIMAL(7,4),
ATO VARCHAR(25),
REASON VARCHAR(25),
DESCRIPTION VARCHAR(2000),
FILES varchar(500),
TOLD CHAR(1),
last_changed timestamp not null default current_timestamp
)

CREATE INDEX JOHNTEST.tl_primary
ON JOHNTEST.TASK_LIST(TASK)

Alter TABLE JOHNTEST.TASK_LIST add constraint primary
PRIMARY KEY(TASK)

Why does the sql statement:

INSERT INTO JOHNTEST.TASK_LIST(TASK, "ATO", "PRI", "SUBP", "DESCRIPTION")
VALUES(default,'Bob', 'z', 999.999, 'testing')

caues the error message:

DB2 SQL error: SQLCODE: -803, SQLSTATE: 23505, SQLERRMC:
1;JOHNTEST.TASK_LIST
Message: 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 "JOHNTEST.TASK_LIST" from having duplicate rows for
those columns. 

I thought my primary key would be generated every time, uniquely

There are a couple of options:
1. At some point an insert was doen providing a value instead of letting
DB2 do it. This value is now cauing a collision.
2. A LOAD was performed which provided the values (OVERRIDE).

Given the flexibility (CYCLE, RESTART, flip INCREMENT, ...) of IDENTITY
DB2 cannot automagically synch up.

Here is a handy proc which you can use to "synch up". The procedure
assumes positive increments:

CREATE PROCEDURE GOODSTUFF.SYNCIDENTITY(IN schemaname VARCHAR(128),
IN tablename VARCHAR(128))
BEGIN
DECLARE sqlcode INTEGER;
DECLARE maxid BIGINT;
DECLARE idcolname VARCHAR(128);
DECLARE stmttxt VARCHAR(1000);
DECLARE s STATEMENT;
DECLARE cur CURSOR FOR s;

SELECT colname INTO idcolname
FROM SYSCAT.COLUMNS
WHERE tabname = tablename
AND tabschema = schemaname
AND identity = 'Y';
IF SQLCODE = 100 THEN
SIGNAL SQLSTATE '78000'
SET MESSAGE_TEXT = 'can''t find identity column';
END IF;
SET stmttxt = 'SELECT MAX("' || idcolname || '") FROM "' ||
schemaname || '"."' || tablename || '"';
PREPARE s FROM stmttxt;
SET maxid = 0;
OPEN cur;
FETCH cur INTO maxid;
CLOSE cur;
SET stmttxt = 'ALTER TABLE "' || schemaname || '"."'
|| tablename || '" ALTER COLUMN "' || idcolname ||
'" RESTART WITH ' || CHAR(maxid + 1);
EXECUTE IMMEDIATE stmttxt;
COMMIT;
END
$
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4
Serge Rielau wrote:
Bob Stearns wrote:
Given the DDL:

CREATE TABLE JOHNTEST.TASK_LIST (
TASK BIGINT GENERATED BY DEFAULT AS IDENTITY
(START WITH 1, INCREMENT BY 1, CACHE 20) NOT NULL,
PRI CHAR(1) NOT NULL,
SUBP DECIMAL(7,4),
ATO VARCHAR(25),
REASON VARCHAR(25),
DESCRIPTION VARCHAR(2000),
FILES varchar(500),
TOLD CHAR(1),
last_changed timestamp not null default current_timestamp
)

CREATE INDEX JOHNTEST.tl_primary
ON JOHNTEST.TASK_LIST(TASK)

Alter TABLE JOHNTEST.TASK_LIST add constraint primary
PRIMARY KEY(TASK)

Why does the sql statement:

INSERT INTO JOHNTEST.TASK_LIST(TASK, "ATO", "PRI", "SUBP", "DESCRIPTION")
VALUES(default,'Bob', 'z', 999.999, 'testing')

caues the error message:

DB2 SQL error: SQLCODE: -803, SQLSTATE: 23505, SQLERRMC:
1;JOHNTEST.TASK_LIST
Message: 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 "JOHNTEST.TASK_LIST" from having
duplicate rows for those columns. 

I thought my primary key would be generated every time, uniquely


There are a couple of options:
1. At some point an insert was doen providing a value instead of letting
DB2 do it. This value is now cauing a collision.
2. A LOAD was performed which provided the values (OVERRIDE).

Given the flexibility (CYCLE, RESTART, flip INCREMENT, ...) of IDENTITY
DB2 cannot automagically synch up.

Here is a handy proc which you can use to "synch up". The procedure
assumes positive increments:

CREATE PROCEDURE GOODSTUFF.SYNCIDENTITY(IN schemaname VARCHAR(128),
IN tablename VARCHAR(128))
BEGIN
DECLARE sqlcode INTEGER;
DECLARE maxid BIGINT;
DECLARE idcolname VARCHAR(128);
DECLARE stmttxt VARCHAR(1000);
DECLARE s STATEMENT;
DECLARE cur CURSOR FOR s;

SELECT colname INTO idcolname
FROM SYSCAT.COLUMNS
WHERE tabname = tablename
AND tabschema = schemaname
AND identity = 'Y';
IF SQLCODE = 100 THEN
SIGNAL SQLSTATE '78000'
SET MESSAGE_TEXT = 'can''t find identity column';
END IF;
SET stmttxt = 'SELECT MAX("' || idcolname || '") FROM "' ||
schemaname || '"."' || tablename || '"';
PREPARE s FROM stmttxt;
SET maxid = 0;
OPEN cur;
FETCH cur INTO maxid;
CLOSE cur;
SET stmttxt = 'ALTER TABLE "' || schemaname || '"."'
|| tablename || '" ALTER COLUMN "' || idcolname ||
'" RESTART WITH ' || CHAR(maxid + 1);
EXECUTE IMMEDIATE stmttxt;
COMMIT;
END
$

Thanks a lot. I don't use identity keys often (3 times in two years) but
this is a handy tool for when I make a mistake.
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Srinivas B.S.S | last post by:
Hi, I am using MyODBC 3.51.06 on solaris. When a ODBC call fails to execute due to communication problems with database server, according to ODBC reference, sqlstate should be set to 08S01...
2
by: Herbert | last post by:
Hallo colleques, I get during the following error message "SQL1035N No database manager command was issued. SQLSTATE=57019", when issuing the following command on the Command Line Processor:...
5
by: Jean-Marc Blaise | last post by:
Dear all, Could you explain why some SQL messages do not possess a SQLSTATE ? Why not transmitting the SQLSTATE of the original <sqlcode>, for example if you get a -911 on a RUNSTATS ? ...
3
by: Jason Gyetko | last post by:
I'm running DB2 v8.1 FP5 and am trying to link tables via ODBC from Access 2002 to my DB2 database. Access lets me connect to the database and returns a list of all tables I can select from, but...
1
by: xf wang via DBMonster.com | last post by:
when i call db2 store producedure,db2 throws exception whose sqlstate is identical t0 38503.I find information as follows: DB2 does check for certain types of limited actions that erroneously...
2
by: Richard | last post by:
Our web programmer was looking in his application log an found the following error: 2006-08-31 16:33:35,129 ERROR org.hibernate.util.JDBCExceptionReporter - < SQL0723N An error occurred in a...
4
by: Pool | last post by:
I tried to connect DB2 (Sitting in Unix server at my client location) using Db2 connect V8. I am getting the following error message. I tried all the possible options BUt the error is same.. See each...
2
by: skt | last post by:
CREATE PROCEDURE NYCIKCP.LIB_SEQUNCE_GEN(IN "@ADB_DIVISION" VARCHAR(32)) SPECIFIC LIB_SEQUNCE_GEN MODIFIES SQL DATA NOT DETERMINISTIC NULL CALL LANGUAGE SQL BEGIN DECLARE SQLSTATE CHAR(5)...
1
by: Rudolf Bargholz | last post by:
Hi, We have created triggers to log modifications to tables in our application. The triggers work fine, just on one of the tables in our database the triggers fail with the error message...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.