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 > alter a row change timestamp column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-10-10, 14:22
gwilper gwilper is offline
Registered User
 
Join Date: Mar 2003
Posts: 2
alter a row change timestamp column

DB2 9 for z/OS

I have a table with a ROW CHANGE TIMESTAMP column on it that was defined as GENERATED BY DEFAULT. Is there anyway to alter this column and change it to GENERATED ALWAYS? I thought the following might do it:

ALTER TABLE "TDKGROUP"
ALTER COLUMN "SYS_GEN_TMSTMP" SET GENERATED ALWAYS;

But I received the following:

DSNT408I SQLCODE = -20180, ERROR: COLUMN SYS_GEN_TMSTMP IN TABLE
ASLDB2.TDKGROUP CAN NOT BE ALTERED AS SPECIFIED

I think this alter may only work on generated identity columns. Any suggestions? I'm trying to avoid dropping the table.

Last edited by gwilper; 09-10-10 at 16:07.
Reply With Quote
  #2 (permalink)  
Old 09-10-10, 16:57
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
gwilper, I am not sure you have any other choice. According to Info center topic DB2 V9.1 - DB2 SQL - ALTER TABLE:

A column cannot be altered if any of the following conditions are true:

The column is defined as a row change timestamp column

You will have to scroll down a bit to get to the text on ALTER COLUMN column-alteration.
Reply With Quote
  #3 (permalink)  
Old 09-10-10, 22:28
DB2Plus DB2Plus is offline
Registered User
 
Join Date: Jul 2009
Posts: 150
You have to define column SYS_GEN_TMSTMP Timestamp not Null with default.

Then, when you insert values into TDKGROUP use this simple query:

Quote:
Insert Into TDKGROUP
(other columns, SYS_GEN_TMSTMP)
values(other values, timestamp(generate_unique))
Could be also something like this (DB2 V9):

Quote:
SYS_GEN_TMSTMP NOT NULL
GENERATED ALWAYS FOR EACH ROW ON UPDATE
AS ROW CHANGE TIMESTAMP
Kara

Last edited by DB2Plus; 09-11-10 at 01:19.
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