IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Addin a column to a table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Wed Jul 09, 2008 1:47 pm
Reply with quote

Hello
I have a table that has a VARCHAR column as the last one.
Now I need to add a new column to that table. It will be a unique INDEX used very often.
The question is: Should I add it to the end or, put it just before the VARCHAR?

Thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jul 09, 2008 2:06 pm
Reply with quote

how would you 'put it before the varchar column'?
Back to top
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Wed Jul 09, 2008 2:10 pm
Reply with quote

Quote:
how would you 'put it before the varchar column'?

I need to DROP the table, and CREATE it again. If I put it at the end, I only need an ALTER TABLE.
Back to top
View user's profile Send private message
Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 107
Location: New York

PostPosted: Wed Jul 09, 2008 7:47 pm
Reply with quote

Hi

Putting at the last will reduce lot of your efforts.

Advantages:

1) You do not need to drop the table. As you said you can add using Alter command
2) Also, if the table has data, then you will lose all the data, if you drop it.
3) If you are UNLOADing the data and after making changes to the table, you cannot load the same data in to the table using LOAD utility since a column is added in the middle.
4) Code change will be minimal.
Back to top
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Wed Jul 09, 2008 7:59 pm
Reply with quote

Thanks.
I suppose the performance will not be affected one way or the other.
Back to top
View user's profile Send private message
Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 107
Location: New York

PostPosted: Wed Jul 09, 2008 8:05 pm
Reply with quote

Yes.. Performance would not be different in either of the way.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jul 09, 2008 8:26 pm
Reply with quote

IBM suggests always putting VARCHAR at end. So, I image there will be some performance impact if the new column is at the end.

if nothing else, you can not always insure that you will not have a tablescan on the new (at the end) column, which by definition is in a 'variable' place. db2 can handle it, just requires a little more code.


Loading a new table, after unloading, dropping, creating is not impossible, actually it is not that hard--------otherwise no one would drop/create w/new column.

I am not a dba, you need to speak to your dba about the easiest way to repopulate your new table.

If you are really stuck, create a table under your userid that matches the old.
Code:

INSERT into yours
select *
from old

then drop the old, create a new, 
 
INSERT into new
 Select col1
        , col2
        , col3
        , literal for new column
        , col4
from your table.


When this is migrated to production, let the dba's worry about the new table.
Back to top
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Wed Jul 09, 2008 9:01 pm
Reply with quote

I'm not worried about preserving the contents of the table.
One way or the other, I will migrate the data.
My only concern is with performance.
The column will be a unique index, and will be used as a condition and also in a "order by" clause in a cursor.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
Search our Forums:

Back to Top