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 table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-04, 10:16
JDionne JDionne is offline
Registered User
 
Join Date: Aug 2002
Location: Charlotte NC
Posts: 663
Alter table

I have been looking to alter a column in a table and add a default value. Im trying to find a good script example to do this. my question now is why cant I do it in the GUI tool? When I select the table select alter and then select the column and press alter everything is grayed out. Im logging in as the admin in the sysadmin group. any thoughts as to why the qui will not let me alter the table?
Jim
__________________
------------
And back to SQL Server....I always find my way home
View my Linkedin profile
Reply With Quote
  #2 (permalink)  
Old 07-23-04, 10:41
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You can add a column, but you cannot alter a column (except to change the length of a varchar column). This may change in version 8.2 (Stinger) due out later this year.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 07-23-04, 10:47
JDionne JDionne is offline
Registered User
 
Join Date: Aug 2002
Location: Charlotte NC
Posts: 663
Quote:
Originally Posted by Marcus_A
You can add a column, but you cannot alter a column (except to change the length of a varchar column). This may change in version 8.2 (Stinger) due out later this year.
OK I accept that. Can you help me with an alter table script. I cant seem to find a good example to base mine off of.
Jim
__________________
------------
And back to SQL Server....I always find my way home
View my Linkedin profile
Reply With Quote
  #4 (permalink)  
Old 07-23-04, 10:53
dsusendran dsusendran is offline
Registered User
 
Join Date: Apr 2004
Location: Inside Intel
Posts: 165
Talking

You HAVE to drop and recreate them.

Newbie
Reply With Quote
  #5 (permalink)  
Old 07-23-04, 10:57
JDionne JDionne is offline
Registered User
 
Join Date: Aug 2002
Location: Charlotte NC
Posts: 663
Quote:
Originally Posted by dsusendran
You HAVE to drop and recreate them.

Newbie
You have to be kidding me. I cant accept that I cant add a default after the table is created. I mean for gods sake i have the table populated.
Jim
__________________
------------
And back to SQL Server....I always find my way home
View my Linkedin profile
Reply With Quote
  #6 (permalink)  
Old 07-23-04, 11:13
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
God has nothing to do with it, and YOU WILL ACCEPT IT.

However, it is quite easy to do the following (assume your table is called table_name)

create new table called table_name2 the way you want all the columns defined.

insert into table_name2 select * from table_name
(if the table is very large and you don't want to log the inserts, then use not logged initially and execute the insert in the same unit of work, and then commit)

rename table table_name to table_name3

rename table table_name2 to table_name

create indexes, views, rebind, etc
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #7 (permalink)  
Old 07-23-04, 11:21
JDionne JDionne is offline
Registered User
 
Join Date: Aug 2002
Location: Charlotte NC
Posts: 663
Quote:
Originally Posted by Marcus_A
God has nothing to do with it, and YOU WILL ACCEPT IT.

However, it is quite easy to do the following (assume your table is called table_name)

create new table called table_name2 the way you want all the columns defined.

insert into table_name2 select * from table_name
(if the table is very large and you don't want to log the inserts, then use not logged initially and execute the insert in the same unit of work, and then commit)

rename table table_name to table_name3

rename table table_name2 to table_name

create indexes, views, rebind, etc

I am still in complete shock that I have to do all off this just to add a default. Ill remember to have this worked out before i creat the next batch of tables.
Jim
__________________
------------
And back to SQL Server....I always find my way home
View my Linkedin profile
Reply With Quote
  #8 (permalink)  
Old 07-23-04, 11:24
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You need to think carefully about any data integrity problems that might occur with changes to the existing values of the table if you switch to new default value. I think this may be why changing it on the fly is not allowed.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #9 (permalink)  
Old 07-23-04, 11:32
JDionne JDionne is offline
Registered User
 
Join Date: Aug 2002
Location: Charlotte NC
Posts: 663
Quote:
Originally Posted by Marcus_A
You need to think carefully about any data integrity problems that might occur with changes to the existing values of the table if you switch to new default value. I think this may be why changing it on the fly is not allowed.

Unfortunatly the issue was not discused before the table was created and now there is a need for a default value. I didnt change an exhisting one, i needed to create one.
Thanks for all the help
Jim
__________________
------------
And back to SQL Server....I always find my way home
View my Linkedin profile
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