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 > can db2 luw v9.5 express-c support alter column from integer to identity?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-09, 02:25
wrl wrl is offline
Registered User
 
Join Date: Apr 2009
Posts: 4
Red face can db2 luw v9.5 express-c support alter column from integer to identity?

i have a table which primary key is an integer column with generated by default property.

i now want to move data from the table to a new one, but the problem is if i just perform insert and select data from the old one, the primary key of the new table would different from the old table.

can i create the new table with primary key is integer at first, and then change its type from integer to identity column after inserting data from the old table?

my db2 version is LUW v9.5 express-c, thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 04-03-09, 03:04
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
better you can load data into the new table using the LOAD command with an IDENTITYOVERRIDE option.... faster and easier...

Check this link out -
DB2 Universal Database
__________________
IBM Certified Database Associate, DB2 9 for LUW
Reply With Quote
  #3 (permalink)  
Old 04-03-09, 03:23
wrl wrl is offline
Registered User
 
Join Date: Apr 2009
Posts: 4
Unhappy

i would but i couldn't, as i'm not the dba of the old database, all i can do is just export each table to an ixf file and then load into the new dabase one by one.

i've tried to use the statement stated in ibm's manual as below,

alter table ppm.table1 alter column col1 set GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1, NO CACHE );

but it failed and returned database not support, but i get this statement from ibm's sql manual for v9.5.

any idea?
Reply With Quote
  #4 (permalink)  
Old 04-03-09, 04:07
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
If you have a GENERATED BY DEFAULT clause, you can insert whichever values you like - DB2 won't block you (as long as the data type is valid and check constraints are not violated). Things are different with GENERATED ALWAYS, of course.

Regarding the "not supported", it would be extremely helpful if you would post the complete error message. But my guess is that your edition just doesn't have this feature available. The documentation describes all features for the full DB2 edition (enterprise server edition) but you don't have that.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 04-03-09, 06:10
wrl wrl is offline
Registered User
 
Join Date: Apr 2009
Posts: 4
Lightbulb

Thanks for your kind advise, and I have got an idea from your answer.

Regarding to the "not supported" problem, please find the SQL I executed below,

create table ppm.twrl(col1 integer, col2 char(50));
insert into ppm.twrl values(11, 'string1'),(12, 'string2'),(13, 'string3'),(14, 'string4'),(15, 'string5');
alter table ppm.twrl alter column col1 set GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1, NO CACHE );

then I got the error return as,

SQL0270N Function not supported (Reason code = "72"). SQLSTATE=42997

0 Row(s) affected

CLI0125E Function sequence error. SQLSTATE=S1010


but please be reminded that the testing machine is DB2 Enterprise V9.1.5

Database server = DB2/AIX64 9.1.5
Reply With Quote
  #6 (permalink)  
Old 04-03-09, 09:46
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
Your problem is totally different

Reason code 72 is
Quote:
A nullable column cannot be changed to become an identity column.
so tweak your first statement to
Quote:
create table ppm.twrl(col1 integer not null, col2 char(50));
that is bcoz generated by identity columns can never be null bcoz they are defined to be so..... also since your column col1 can hold null values, the consistency check fails for existing rows on issuing the alter table command....
__________________
IBM Certified Database Associate, DB2 9 for LUW
Reply With Quote
  #7 (permalink)  
Old 04-04-09, 05:22
wrl wrl is offline
Registered User
 
Join Date: Apr 2009
Posts: 4
sorry about that, i haven't traced the reason after got the error code.

thanks you all for investigation!
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