Page 1 of 1

what is sql code to delete column ?

PostPosted: Sat Jul 31, 2010 6:46 pm
by ballaravi
what is sql code to delete column in db2?

Re: what is sql code to delete column ?

PostPosted: Sat Jul 31, 2010 10:08 pm
by NicC
I am not sure if you can delete a column unless it has come in in recent versions of DB2. The normal way is to drop the table and recreate it with the new definition.

Re: what is sql code to delete column ?

PostPosted: Sun Aug 01, 2010 5:17 am
by dick scherrer
Hello,

There are often problems with terminology - what does "delete a column" mean to you?

Re: what is sql code to delete column ?

PostPosted: Mon Aug 09, 2010 8:07 pm
by ballaravi
just consider in an EMP table i have columns (empno,empname,salary,deptno).
now i dont what to deptno on the EMP table, how to delete that column.

Re: what is sql code to delete column ?

PostPosted: Mon Aug 09, 2010 8:30 pm
by NicC
1) unload the data from the current table but ignore the data in the column that you do not want
2) drop the table
3) recreat the table with the new definition
4) load the table from the saved data

Re: what is sql code to delete column ?

PostPosted: Tue Aug 10, 2010 4:23 pm
by ballaravi
ok,good idea only, but in sql server and oracle we can delete the column direcly, need of above septs, why it is not in db2. thats why i asked.if we have more data it is difficcult one..

ok thank you... for ur answer.. :)

Re: what is sql code to delete column ?

PostPosted: Mon Sep 20, 2010 10:37 pm
by R.V.N.REDDY
ALTER TABLE table_name DELETE COLUMN column-name


This is the command used to delete the existing column from the table

Re: what is sql code to delete column ?

PostPosted: Mon Sep 20, 2010 11:48 pm
by NicC
ALTER TABLE table_name DELETE COLUMN column-name


Which version of DB2 is this from? I have checked the ALTER TABLE syntax in version 8 and column deletion is NOT supported.

Re: what is sql code to delete column ?

PostPosted: Tue Sep 21, 2010 12:17 am
by dick scherrer
Hello,

IIRC, this is is from DB2 LUW, not mainframe. . .