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 > VERY URGENT - need to set up alter statements

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-20-04, 21:08
prithvi_raj prithvi_raj is offline
Registered User
 
Join Date: Apr 2004
Posts: 36
Angry VERY URGENT - need to set up alter statements

Hi,
I am trying to generate a sql which sets the values of identity columns with the max value +1 of the column.

The statement looks like this.

Alter table alter column col_name ( select max(col_name)+1 from table );

This kind of statements i have to generate for 4 schemas.
Can any one give me one example of how do i generate this one.
I have got problems in generating this.

Its UDB8.1 fp5 , sol os..
Reply With Quote
  #2 (permalink)  
Old 07-20-04, 21:29
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
SQL does not support this type of operation ...

From the command prompt you may issue
db2 "alter table tid alter column i restart with `db2 -x select max\(i\) from tid` "

where tid is the tablename and i is the identity column name ...

HTH

sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 07-20-04, 21:42
prithvi_raj prithvi_raj is offline
Registered User
 
Join Date: Apr 2004
Posts: 36
Sathya , i need to generate it for all the tables for 4 schemas.
Can you give me me more detailed example , which i can directly run at command prompt.
Reply With Quote
  #4 (permalink)  
Old 07-20-04, 21:56
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Code:
db2 -x "select rtrim(tabschema)||'.'||rtrim(tabname) ,colname from syscat.columns where identity='Y'" |  while read tname tcol
do
db2 -v "alter table $tname alter column $tcol restart with `db2 -x select coalesce\(max\($tcol\),0\)+1 from $tname`"
done
Hope this helps

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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