Dropping a column

We are planning to drop a column from a production large table with more than 150 million rows.
It is causing an exclusive lock on the table for more than 2 hrs. Is there any way we can reduce the time period for the lock on the table.
We tried setting the column unused and then dropping it but it also causing the lock on the table for hrs.
Is there any way we can drop the column without causing exclusive lock on the same or we can shorten this time.

I see you can have two approaches and you can choose which best suites you.
1) DBMS_REDEFINITION
2) Using triggers to capture DML statements along with CTAS.
First approach is an easier approach but is time consuming.
I do not think so you can have downtime for DML operations during dropping of the column.
Regards
Anurag

Similar Messages

  • Dropping unused columns from database table

    I have an existing table called TUSER. I have mapped some fields, but not
    all fields, as some are inserted by other applications and for reporting
    purposes.
    I am using JDK 1.3.1_02, Windows 2000, SQL Server 2000 database, Kodo
    JDOEE 2.2.6 and JBoss 3.0.0.
    When I refresh the datastore it drops all columns that are not mapped
    (note that these colums can contain null values):
    [java] [ connection: 2961925; statement: 2766626; time: Thu Jul 04
    15:33:22 JST 2002 ] ALTER TABLE TUSER ADD Job_Title_ID VARCHAR(255)
    [java] [ connection: 2961925; statement: 1582473; time: Thu Jul 04
    15:33:22 JST 2002 ] ALTER TABLE TUSER DROP COLUMN MAILUSERID
    [java] [ connection: 2961925; statement: 5237832; time: Thu Jul 04
    15:33:22 JST 2002 ] ALTER TABLE TUSER DROP COLUMN PHONENUMBERS
    [java] [ connection: 2961925; statement: 2191491; time: Thu Jul 04
    15:33:22 JST 2002 ] ALTER TABLE TUSER DROP COLUMN EMPLOYEENO
    [java] [ connection: 2961925; statement: 894443; time: Thu Jul 04
    15:33:22 JST 2002 ] ALTER TABLE TUSER DROP COLUMN MDATE
    [java] [ connection: 2961925; statement: 531758; time: Thu Jul 04
    15:33:22 JST 2002 ] ALTER TABLE TUSER DROP COLUMN STATUSCHANGETIME
    [java] [ connection: 2961925; statement: 5899013; time: Thu Jul 04
    15:33:23 JST 2002 ] ALTER TABLE TUSER DROP COLUMN FINISHDATE
    [java] [ connection: 2961925; statement: 8146001; time: Thu Jul 04
    15:33:23 JST 2002 ] ALTER TABLE TUSER DROP COLUMN LASTLOGGEDMBOARD
    [java] [ connection: 2961925; statement: 7756310; time: Thu Jul 04
    15:33:23 JST 2002 ] ALTER TABLE TUSER DROP COLUMN DEL_FLG
    [java] [ connection: 2961925; statement: 6817858; time: Thu Jul 04
    15:33:23 JST 2002 ] ALTER TABLE TUSER DROP COLUMN PERMIT_CD
    [java] [ connection: 2961925; statement: 7754670; time: Thu Jul 04
    15:33:23 JST 2002 ] ALTER TABLE TUSER DROP COLUMN LASTLOGGEDREQUESTER
    [java] [ connection: 2961925; statement: 7332084; time: Thu Jul 04
    15:33:24 JST 2002 ] ALTER TABLE TUSER DROP COLUMN MSG_SERVER
    [java] [ connection: 2961925; statement: 1691809; time: Thu Jul 04
    15:33:24 JST 2002 ] ALTER TABLE TUSER DROP COLUMN AUTORUN
    [java] [ connection: 2961925; statement: 5253969; time: Thu Jul 04
    15:33:24 JST 2002 ] ALTER TABLE TUSER DROP COLUMN REG_DATE
    [java] [ connection: 2961925; statement: 4977422; time: Thu Jul 04
    15:33:24 JST 2002 ] ALTER TABLE TUSER DROP COLUMN PERMIT_LST
    [java] [ connection: 2961925; statement: 4343712; time: Thu Jul 04
    15:33:24 JST 2002 ] ALTER TABLE TUSER DROP COLUMN ALLOWREPL
    [java] [ connection: 2961925; statement: 7104150; time: Thu Jul 04
    15:33:24 JST 2002 ] ALTER TABLE TUSER DROP COLUMN EMAIL
    [java] [ connection: 2961925; statement: 4395840; time: Thu Jul 04
    15:33:24 JST 2002 ] ALTER TABLE TUSER DROP COLUMN MANAGERSTATUS
    [java] [ connection: 2961925; statement: 2417379; time: Thu Jul 04
    15:33:24 JST 2002 ] ALTER TABLE TUSER DROP COLUMN MD5_DIGEST
    [java] [ connection: 2961925; statement: 2865120; time: Thu Jul 04
    15:33:25 JST 2002 ] ALTER TABLE TUSER DROP COLUMN SMTPADDRESS
    15:33:25 JST 2002 ] INSERT INTO JDO_SCHEMA_METADATAX(CLASSNAMEX) VALUES
    ('com.gulfnet.g
    roupcast.data.User')
    Is this meant to happen? I am guessing not. Is there a way to tell the
    schematool to not remove existing columns?
    Thanks in advance.
    Kam

    You can in fact tell the schematool not to drop columns it doesn't know about. When you run the schematool, use the "add" action rather than "refresh". Then it will only add columns, never drop them. See the documentation for details:
    http://www.solarmetric.com/Software/Documentation/2.2.5/manual.html#schema_manipulation

  • Cannot drop a column

    Hi,
    I am having a problem with dropping a column from a table. I am using 10g (10.2.0.1.0). Whenever I try to drop a column I got this error:
    ORA-39726: unsupported add/drop column operation on compressed tables
    Then I tried to drop it in a way that first make it unused and then drop it but this time I got the following erro: while unused operation was successful
    ORA-12996: cannot drop system-generated virtual column
    Well I restored this database from RMAN backups of my production system. One thing more that is, when I created a new table then from that table I can drop or add any column from/to it.
    Any help........
    Arshad.

    Well I have already tried this. As I explained in my first email that unused worked fine but as soon as I try to drop the unused column I got this error:
    ORA-12996: cannot drop system-generated virtual column
    Arshad.

  • Drag-drop data column sorting

    Hey guys,
    Does any one know how to achieve drag-drop data column
    sorting? I tried, but could not find an efficient way to do this.
    It would be an awesome spry feature if possible, but if someone
    else knows how to do this already it would help.
    Thanks,
    Timothy D Farrar

    Hey guys,
    We aim to be as compatible as possible with the other
    frameworks but sometimes problem may exists. We need to see the
    crashing pages to be able to determine the causes for the JS error
    message and where the incompatibilities are located and either fix
    the problems or help you to change your pages to work.
    In this situation I suspect the issue appears because the
    spry region is generated after the drag and drop code from the
    script.aculo.us is instantiated and we destroy the initial elements
    to which this widget is binded. In this situation the solution is
    to instantiate the drag and drop after the region generate its
    content by using the region observers. You'll have to put the drag
    and into a separated function and register the code so the region
    will call it automatically onPostUpdate.
    We include in our documentation more details about the
    Region
    observer notifications. Please search the dedicated chapter
    inside this doc: "Region observer notifications"
    Regards,
    Cristian MARIN

  • Dropping a column in composite xmltype table with virtual column

    Hello,
    i found some interesting behavior. I have a table with xmltype column and a virtual column. If i drop a column, which has an index smaller than the index for the xmltype column, than the virtual column reference for xmltype column is not changed.
    select * from v$version;
    drop table t_xml purge;
    create table t_xml( c1 number,
                        c2 number,
                        cxml xmltype,
                        c3 number,
                        xmlflag number as (nvl2(cxml,1,0)));
    select * from t_xml;
    alter table t_xml drop column c2;                    
    select * from t_xml; The 2nd select will result in error:
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL> alter table t_xml drop column c2;                    
    Tabelle wurde geändert.
    SQL>
    SQL> select * from t_xml;
    select * from t_xml
    FEHLER in Zeile 1:
    ORA-00904: "SYS_NC00004$": ungültiger BezeichnerNow the virtual column xmlflag references still the old hidden column for cxml (SYS_NC00004$). It not references the new hidden column, which is now SYS_NC00003$.
    I think, it is a bug! Can someone inform oracle? I have no access to metalink.

    Hi,
    Please try this code:
    loop at int_inv into wa_inv.
        lv_count = lv_count + 1.
        AT END OF posnr.   <------- The field you want to sum..
          gs_total-posnr      = wa_inv-posnr.
          gs_total-cov_total  = lv_count.
          APPEND gs_total TO gt_total.
          CLEAR : gs_total,
                  lv_count,
                  wa_inv.
        ENDAT.
      ENDLOOP.

  • Dropping Unused column

    Hi All,
    I am working on version 11.2.0.3.0 ( windows server 2008 ).
    While dropping unused column i am getting below error
    SQL> create table er (ab varchar2(50), aa varchar2(50)) compress;
    SQL> alter table er set unused column ab;
    Table altered.
    SQL>
    SQL>
    SQL>
    SQL>
    SQL> alter table er drop unused columns;
    alter table er drop unused columns
    ERROR at line 1:
    ORA-39726: unsupported add/drop column operation on compressed tables

    i can't do such things for these number of tablesThat is the funniest thing I've heard in a while. If you can "alter table xxx drop unused columns," why can't you do what is suggested.
    And no, it's not a bug.
    And no, there is not "another way around"

  • Drop unused column in compressed table

    Good day for all.
    I have partitioned compressed table under 10.2.0.4 database. I need to remove column, and did it according metalink note 429898.1, but then i execute command alter table .... drop unused columns, i got error ORA-39726 (unsupported add/drop column operation for compreseed table), so it mean that proposed workaround don't works now.
    Does anyone have new workaround for this problem?

    alter table MY_TABLE set unused(MY_FNG_COLUMN);
    -- success
    alter table MY_TABLE drop unused columns;
    -- error

  • How to drop a column

    Hi OTNeites,
    How does one drop a column in Oracle 7.2 or Oracle 8.0
    Thanks in advance.

    Something like this.
    create new_table as select col1, col2, col3
    from old_table
    drop old_table
    rename new_table to old table
    The trick is to select all the columns except the one you want to drop when creating the new table.
    In this case you lost all indexes, constraints ...
    You should create script for recriate all objects in DB
    that will be drop with DROP OLD_TABLE command.

  • Dropping a column's default value

    How to drop a column's default value?
    The following commands fails:
    ALTER TABLE t1 ALTER COLUMN c1 DROP DEFAULT.
    ALTER TABLE t1 MODIFY c1 DROP DEFAULT.
    Thanks in advance.

    SQL> ALTER TABLE IDENTIFICADORES_DOMINIOS_RANGO MODIFY TIPO_DATO DEFAULT NULL;
    Table altered
    SQL> DESC IDENTIFICADORES_DOMINIOS_RANGO
    Name                 Type         Nullable Default Comments                                  
    CODIGO_IDENTIFICADOR NUMBER(7)                                                               
    DESCRIPCION          VARCHAR2(50)                                                            
    TIPO                 VARCHAR2(1)                                                             
    TIPO_DATO            VARCHAR2(1)           NULL    Tipo de dato que contiene el Dominio-RangoI would like drop DEFAULT value; now, it's marked like NULL. It's not the same... is it?

  • ORA-12983: cannot drop all columns in a table

    Hi,
    I am creating a table with two columns.
    I have modified a column as unused using ALTER statement.
    After that i have tried to drop the another column by using ALTER statement.
    But it throws an error ORA-12983: cannot drop all columns in a table.
    is it not possible to achieve this via ALTER statement?
    thanks

    is there any other way to find the name of the columns which have been marked as unused?Don't think so, and you would not be able to do much about. You won't be able to reference it, you won't be able to un-unuse it, and you would even be able to add a new column having same name.
    Why are you using SET UNUSED in the first place?
    Regards
    Peter
    Quoting myself:
    You won't be able to reference itMaybe not good enough:
    SQL> select column_name, data_type, segment_column_id
      from user_tab_cols
    where table_name = 'T';
    COLUMN_NAME                    DATA_TYPE   SEGMENT_COLUMN_ID
    SYS_C00001_11051618:28:14$     NUMBER                      1
    B                              NUMBER                      2
    SYS_C00003_11051618:28:14$     NUMBER                      3
    3 rows selected.
    select "SYS_C00003_11051618:28:14$" from t
    Error at line 1
    ORA-00904: "SYS_C00003_11051618:28:14$": invalid identifier
    SQL> alter table t drop column "SYS_C00001_11051618:28:14$";
    Table altered.
    SQL> select column_name, data_type, segment_column_id
      from user_tab_cols
    where table_name = 'T';
    COLUMN_NAME                    DATA_TYPE   SEGMENT_COLUMN_ID
    B                              NUMBER                      
    1 row selected.
    Note: Both columns "disappeared"  Thanks MichaelS
    Edited by: Peter on May 16, 2011 9:29 AM

  • Dropping a column generate redo?

    wheather dropping a column from table will generate redo?

    16:14:12 jaffar@PRIMEDB> create table dept22 as select * from dept;
    Table created.
    select a.statistic#,b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name like '%redo%';
    STATISTIC# NAME VALUE
    72 redo synch writes 1
    73 redo synch time 0
    114 redo entries 48
    115 redo size 18704 ==>>
    16:17:20 jaffar@PRIMEDB> drop table dept22;
    Table dropped.
    Elapsed: 00:00:00.00
    slect a.statistic#,b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name like '%redo%';
    STATISTIC# NAME VALUE
    72 redo synch writes 2
    73 redo synch time 0
    114 redo entries 83
    115 redo size 26312 ==>> Oh no... redo on dropping table.
    16:17:44 jaffar@PRIMEDB> create table dept22 as select * from dept;
    Table created.
    Elapsed: 00:00:00.01
    select a.statistic#,b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name like '%redo%';
    STATISTIC# NAME VALUE
    72 redo synch writes 3
    73 redo synch time 0
    114 redo entries 139
    115 redo size 45144 ==>>
    16:18:07 jaffar@PRIMEDB> alter table dept22 drop column deptno;
    Table altered.
    select a.statistic#,b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name like '%redo%';
    STATISTIC# NAME VALUE
    72 redo synch writes 4
    73 redo synch time 0
    114 redo entries 171
    115 redo size 52400 ==>> Oh no.. on dropping column, also generates redo???
    Kulji, you would have done the test before you answer.
    Jaffar
    Message was edited by:
    Syed Jaffar

  • DROP UNUSED COLUMN

    Dear Guru’s
    I have a situation where I need to drop specific columns which are set to unused!
    Say, I have 3 unused columns in a table – and now I want to drop only one unused column from that.
    SQL> alter table scott.emptest set unused (ENAME);
    Table altered.
    SQL> alter table scott.emptest set unused (COMM);
    Table altered.
    Once I set some columns un-used, now I want to drop only one un-used Column “ENAME”
    SQL> alter table scott.emptest drop column ENAME;
    alter table scott.emptest drop column ENAME
    ERROR at line 1:
    ORA-00904: "ENAME": invalid identifier
    which in turn throws this error!
    Help appreciated!
    Thanks in advanced
    Ravi Prakash

    SCOTT@demo102> create table tbl_25 as select * from emp
    SCOTT@demo102> /
    Table created.
    SCOTT@demo102> desc tbl_25
    Name                                      Null?    Type
    EMPNO                                              NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO                                             NUMBER(2)
    SCOTT@demo102> alter table tbl_25 set unused (deptno)
    SCOTT@demo102> /
    Table altered.
    SCOTT@demo102> alter table tbl_25 set unused (comm);
    Table altered.
    SCOTT@demo102> desc tbl_25
    Name                                      Null?    Type
    EMPNO                                              NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    SCOTT@demo102> select * from all_unused_col_tabs where table_name ='TBL_25';
    OWNER                          TABLE_NAME                          COUNT
    SCOTT                          TBL_25                                  2
    SCOTT@demo102> alter table tbl_25 drop unused column;
    Table altered.
    SCOTT@demo102> select * from all_unused_col_tabs where table_name ='TBL_25';
    no rows selected
    SCOTT@demo102> Nicolas.
    Add queries on all_unused_col_tabs.
    Message was edited by:
    N. Gasparotto

  • Dynamic Table using drag and drop table columns

    Hi,
    I want to create an ADF table which allows me to insert new columns from the list of columns.
    List of columns will be shown in the tree. I would like to drag a tree node to the table, table should highlight where i can drop the node.
    Once, i drop it, table should get refreshed with new column at inserted location.
    Is it possible? How?
    Regards,
    Suresh

    Hi,
    I don't think that a drop indicator is possible to create because the drag and drop is no from within the table but from external. You could add the drop target to the table and then determine the column that this is dropped onto. Based on this you can e.g. device to drop it to the right or left
    Frank

  • How to drop a column in Oracle 7i

    I tried
    "alter table tablename drop column columnname" in Oracle 7i, it is not working.
    Column is nullable
    Could anyone pls help me on this?

    any luck finding the v6 doc online?
    RENAME emp to emp_orig;
    CREATE VIEW EMP as
    select col1, col2... --LEAVE OFF THE COLUMN YOU WANT TO DROP
    from emp_orig;
    GRANT select, insert, update, delete on EMP to ....
    this way, you don't have to drop anything, recreate indexes, deal with downtime, etc.
    better solution, just tell people to ignore the other column. really, what harm can it do?

  • Problem every time i want to drag and drop some columns

    I was working in some columns , then in column properties i uncheck box : Wrap Text from TAB : Styles
    then i save as system-wide default as data type ! i got this message error :
    The current xml is invalid with the following errors: Bad xml instance! <?xml version="1.0"?> <sawsavedformat:metadata xmlns:sawsavedformat="com.siebel.analytics.web/savedformat/v1.1"><sawsavedformat:datatypeSavedFormats><sawsavedformat:datatypeFormat xmlns:saw="com.siebel.analytics.web/report/v1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" datatype="GDT:real"><saw:displayFormat><saw:formatSpec suppress="suppress" wrapText="true" visibility="visible" hAlign="right" vAlign="top" imagePlacement="right"><saw:dataFormat xsi:type="saw:number" commas="false" negativeType="minus" minDigits="0" maxDigits="0"/></saw:formatSpec></saw:displayFormat><saw:tableHeading><saw:displayFormat><saw:formatSpec/></saw:displayFormat></saw:tableHeading><saw:columnHeading><saw:displayFormat><saw:formatSpec/></saw:displayFormat></saw:columnHeading></sawsavedformat:datatypeFormat><sawsavedformat:datatypeFormat xmlns:saw="com.siebel.analytics.web/report/v1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" datatype="GDT:text"><saw:displayFormat><saw:formatSpec suppress="suppress" wrapText="false" visibility="visible" hAlign="left" vAlign="top" noWrap="true" imagePlacement="left" interaction="drill"/></saw:displayFormat><saw:tableHeading><saw:displayFormat><saw:formatSpec/></saw:displayFormat></saw:tableHeading><saw:columnHeading><saw:displayFormat><saw:formatSpec interaction="drill"/></saw:displayFormat></saw:columnHeading></sawsavedformat:datatypeFormat></sawsavedformat:datatypeSavedFormats></sawsavedformat:metadata> Line:2, Col:1116, Attribute 'noWrap' is not declared for element 'formatSpec'
    This problem annoying me even i cannot drag and drop to build my Answer Report in some column :( ... teee heeee ... anyone can help me , also a pop up message show this :
    The current xml is invalid with the following errors:
    Bad xml instance!
    <?xml version="1.0"?>
    <sawmd:reportMetadata xmlns:saw="com.siebel.analytics.web/report/v1.1" xmlns:sawx="com.siebel.analytics.web/expression/v1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sawmd="oracle.bi.presentation/reportmetadata/v1" subjectArea="&quot;MINISTRY_STD_ATT&quot;"><sawmd:columnInfo xsi:type="sawmd:regularColumnInfo" columnID="ceb07bca5c4142c11" baseFormula="&quot;EDC_STUDENT_REGISTRATION&quot;.&quot;NOTE&quot;" resolvedFormula="&quot;EDC_STUDENT_REGISTRATION&quot;.&quot;NOTE&quot;" writeEnabled="false" picklistEnabled="false" multivalueEnabled="false"><saw:columnFormula><sawx:expr xsi:type="sawx:sqlExpression">&quot;EDC_STUDENT_REGISTRATION&quot;.&quot;NOTE&quot;</sawx:expr></saw:columnFormula><sawmd:SQLInfo dataType="varchar" nullable="true" aggType="nonAgg" aggRule="none" category="text" primaryType="text" displayFormula="&quot;EDC_STUDENT_REGISTRATION&quot;.&quot;NOTE&quot;" sqlFormula="&quot;MINISTRY_STD_ATT&quot;.&quot;EDC_STUDENT_REGISTRATION&quot;.&quot;NOTE&quot;" hasSortKey="false"/><sawmd:columnDefaults><saw:tableHeading><saw:caption><saw:text>EDC_STUDENT_REGISTRATION</saw:text></saw:caption></saw:tableHeading><saw:columnHeading><saw:caption><saw:text>NOTE</saw:text></saw:caption></saw:columnHeading><saw:displayFormat><saw:formatSpec suppress="suppress" visibility="visible" hAlign="left" vAlign="top" noWrap="true" imagePlacement="left" interaction="drill"/></saw:displayFormat></sawmd:columnDefaults></sawmd:columnInfo></sawmd:reportMetadata>
    Line:2, Col:1402, Attribute 'noWrap' is not declared for element 'formatSpec'

    Hi,
    Did you find a solution to this. I am also seeing the same error in 11g 11.1.1.5
    My Scenario:
    I have drill-in place enabled for a report column and I drill-down on Product Category column to get the breakdown by Product Names. So far good. Then when I click on the 'Analyze' report link I get the below error.
    Error Displaying Results
    The current xml is invalid with the following errors: Bad xml instance!
    This use case was working fine in 10G.
    --Joe                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for