Is there a way to rename columns in a table using SQL. I saw some documentation on IBM's website showing how to do it with ALTER TABLE. When I went to try it some of the options were not available
Announcement
Collapse
No announcement yet.
Rename columns
Collapse
X
-
Originally posted by jj_dahlheimer View PostYou want the label on command.
Comment
-
You could just create a SQL view. Create view Nicename as (Select F1 as Company, F2 as Customer, F3 as Street from FxNames)
This gives the advantage of changing also the fields type, adding new fields or replacing values if needed.
Comment
-
There is a alter table rename function but I don't think db2 for i supports it or at least I couldn't find it. I did see the it for DB2 for LUW.
Couple of things I do in this situation. The view above would work well, could also create the table using the same definitions of the source file while renaming the columns on the create table command.
Code:create or replace table lib/newtable as (select f1 as col1 from lib/oldtable) with data on replace delete rows
Code:insert into lib/newtable (select * from lib/oldtable)
Comment
-
You can accomplish this by first adding a field:
Code:ALTER TABLE TESTTABLE ADD COLUMN ASSET NUMERIC (8 , 0) NOT NULL WITH DEFAULT
Code:UPDATE RAMLIB/TESTTABLE SET ASSET = FANUMB
Code:ALTER TABLE RAMLIB/TESTTABLE DROP COLUMN FANUMB CASCADE
Code:LABEL ON COLUMN RAMLIB/TESTTABLE (ASSET IS 'Asset Number') LABEL ON COLUMN RAMLIB/TESTTABLE (ASSET TEXT IS 'Asset Number')
Code:ALTER TABLE TESTTABLE ADD COLUMN ASSET NUMERIC (8 , 0) NOT NULL WITH DEFAULT; UPDATE RAMLIB/TESTTABLE SET ASSET = FANUMB; ALTER TABLE RAMLIB/TESTTABLE DROP COLUMN FANUMB CASCADE ; LABEL ON COLUMN RAMLIB/TESTTABLE (ASSET IS 'Asset Number') ; LABEL ON COLUMN RAMLIB/TESTTABLE (ASSET TEXT IS 'Asset Number') ;
Comment
Comment