Deleting a column data from table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Srireddy
    New Member
    • Mar 2007
    • 7

    Deleting a column data from table

    Hi all,
    I am trying to delete the data from only one column of a table. can any one help on this.......
  • Snib
    New Member
    • Mar 2007
    • 24

    #2
    Depends whether you mean you want to remove the column from the table altogether or just remove the date in the column,

    If the column is CHAR then do something like this

    UPDATE TABLE_NAME
    SET CHAR_COLUMN = ""

    This will set the column on all rows to an empty string.

    If yuo want to remove a column from the table then that is a little more difficult. Depends on what utilities you have. I would unload the table to a file, drop the table and then redefine the table without the column. Then build a LOAD statement using the data from tbe unload but do not include a reference the values stored for the column you removed.

    If you have a look in some of the DB2 reference guides they will show you the syntax for the LOAD statement, it basically requires you to supply the destination column name, the start position of the data in the file and the length of the field on the file. If you do not supply any column information on the load it assumes the data order, start points and field lengths are in line with structure of the destination table.


    Hope that helps,

    Snib

    Comment

    • ZIA CHOUDHRY
      New Member
      • Dec 2011
      • 1

      #3
      update table_name
      SET column = null

      Comment

      • dineshampili
        New Member
        • Jan 2012
        • 1

        #4
        Try this


        ALTER TABLE table_name
        DROP COLUMN column_name

        Comment

        Working...