If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Temporary tables: Data loss with duplicate records

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-30-04, 04:00
andrewhallam andrewhallam is offline
Registered User
 
Join Date: Dec 2003
Location: Nottingham, England
Posts: 52
Temporary tables: Data loss with duplicate records

DB2 V8.1 on AIX V5.2

I have a .cpp application using ODBC for database interaction.

I create the temp table thus :
"DECLARE GLOBAL TEMPORARY table x_tab (x_col VARGRAPHIC(10)) ON COMMIT PRESERVE ROWS NOT LOGGED"

The index thus :
"CREATE unique index SESSION.x_ind on SESSION.x_tab(x_col)"

I then execute an insert statement :
"insert into SESSION.x_tab (x_col) values (G'x')"

I then execute a count statement :
"select count(*) from SESSION.x_tab"
- This produces 1 - correct.

I then execute another insert statement that will fail due to a duplicate record:
"insert into SESSION.x_tab (x_col) values (G'x')"
- Correctly fails with the below error :

547, <[IBM][CLI Driver][DB2/LINUX] SQL0803N 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 "SESSION.X_TAB" from having duplicate rows for those columns. SQLSTATE=23505

I then execute a second count statement against the temporary table:
"select count(*) from SESSION.x_tab"
- This produces 0 - INCORRECT.

It seems that the 547 error removes all data in the temporary table ???

Anyone come across this ?

We have hundreds of programs that contain temporary tables!.
To get around this I am going to have to dynamically create a select statement against the tamporary tables primary key using the values to be inserted.

I would much rather one of you have a simpler solution for me...

Thanks in advance for any help on this.

Andy.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On