Rename Column in Table

Hi
It's anyway to rename a column name in the Table name?
For info I using Oracle DB 9.2
regards
wisman

Under no circumstances should you change the data dictionary unless:[list=1]
[*]Oracle support tells you to;
[*]you really want to re-build your database.
[list]
Point 2 is not likely but it is a real possibility so take a full backup.
If you are on 8i the proper way to do it is this:[list=1]
[*]ALTER TABLE my_table ADD (new_name varchar2(10));
[*]UPDATE my_table SET new_name = old_name;
[*]ALTER TABLE my_table DROP COLUMN (old_name);
[list]
Obviously you'll need to handle integrity constraints, etc.
If you are on 9i you can do this:
ALTER TABLE my_table RENAME COLUMN old_name TO new_name;Cash back! APC

Similar Messages

  • How i can rename column in table in another name if the table have adata?

     

    1) add new_column with same datatype to table
    2) update table1 set new_col=old_col;
    3) drop column old_col;

  • Rename column name of a table

    Hi Guys,
    I want to rename the column name of a table. Lets say I have table employee:
    SQL> desc emp;
    Name Null? Type
    EMPNO NOT NULL NUMBER(4)
    ENAME VARCHAR2(10)
    JOB VARCHAR2(9)
    MGR NUMBER(4)
    HIREDATE DATE
    SAL NUMBER(7,2)
    COMM NUMBER(7,2)
    DEPTNO NUMBER(2)
    STARS VARCHAR2(8)
    I want to change the name of the cloumn name of ENAME to EMPNAME so that structure looks like this:
    SQL> desc emp;
    Name Null? Type
    EMPNO NOT NULL NUMBER(4)
    EMPNAME VARCHAR2(10)
    JOB VARCHAR2(9)
    MGR NUMBER(4)
    HIREDATE DATE
    SAL NUMBER(7,2)
    COMM NUMBER(7,2)
    DEPTNO NUMBER(2)
    STARS VARCHAR2(8)
    Can anyone tell me any statement or way to solve this problem. Please keep in mind that I will not delete the table or create another column name of EMPNAME and copy the data from ENAME to EMPNAME.
    Regds,
    Debabrata

    ALTER TABLE DEPT2 RENAME COLUMN ENAME TO EMPNAME
    Regards,
    Raj

  • How to rename column name of table?

    Hello...
    How to rename column name of table?
    The column have data.
    Thanks.
    Martonio.

    The following should work in 9i release 2 and above.
    SQL> create table mytable(col1 varchar2(2),
      2  col2 date);
    Table created.
    SQL> insert into mytable values('t1',sysdate);
    1 row created.
    SQL> select * from mytable;
    CO COL2
    t1 30-NOV-04
    1 row selected.
    SQL> desc mytable
    Name                                      Null?    Type
    COL1                                               VARCHAR2(2)
    COL2                                               DATE
    SQL> alter table mytable rename column col2 to mydate;
    Table altered.
    SQL> desc mytable
    Name                                      Null?    Type
    COL1                                               VARCHAR2(2)
    MYDATE                                             DATE
    SQL> select * from mytable;
    CO MYDATE
    t1 30-NOV-04
    1 row selected.
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.3.0 - Productionhttp://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/wnsql.htm#972698

  • Rename column in Oracle 9i

    Can we rename column in Oracle 9i?
    Thanks,
    Alex

    I don't think it should be that complicated unless you have any contraints to it. Do you have any foreign keys that are referencing to this particular table ? Also let me know what syntax are you using for dropping the column ?
    Also look at the following example, try these things on some test/dummt table first.
    Dropping a Column: Example
    ===========================
    This statement illustrates the drop_column_clause with CASCADE CONSTRAINTS. Assume table t1 is created as follows:
    CREATE TABLE t1 (
    pk NUMBER PRIMARY KEY,
    fk NUMBER,
    c1 NUMBER,
    c2 NUMBER,
    CONSTRAINT ri FOREIGN KEY (fk) REFERENCES t1,
    CONSTRAINT ck1 CHECK (pk > 0 and c1 > 0),
    CONSTRAINT ck2 CHECK (c2 > 0)
    An error will be returned for the following statements:
    /* The next two statements return errors:
    ALTER TABLE t1 DROP (pk); -- pk is a parent key
    ALTER TABLE t1 DROP (c1); -- c1 is referenced by multicolumn
    -- constraint ck1
    Submitting the following statement drops column pk, the primary key constraint, the foreign key constraint, ri, and the check constraint, ck1:
    ALTER TABLE t1 DROP (pk) CASCADE CONSTRAINTS;
    If all columns referenced by the constraints defined on the dropped columns are also dropped, then CASCADE CONSTRAINTS is not required. For example, assuming that no other referential constraints from other tables refer to column pk, then it is valid to submit the following statement without the CASCADE CONSTRAINTS clause:
    ALTER TABLE t1 DROP (pk, fk, c1);
    Shalu

  • Renaming columns in 8i

    I have tried in vain to rename a column in 8i. There are no good examples out there. Here's my code
    SQL> DESC KKQA_CLINIC_CD
    Name Null? Type
    CLINIC_CD NOT NULL VARCHAR2(15)
    REC_EFFENDDT NOT NULL DATE
    REC_EFFDT NOT NULL DATE
    IDX_NM VARCHAR2(60)
    DEPT VARCHAR2(30)
    SUBDEPT VARCHAR2(30)
    CLINIC_CD_DESC VARCHAR2(150)
    MIM_CODES_CLINIC VARCHAR2(1)
    HOSPITAL_BASED VARCHAR2(15)
    REG_SOURCE VARCHAR2(15)
    SQL> ALTER TABLE KKQA_CLINIC_CD ADD (CLINIC_CD_EFFENDDT DATE);
    Table altered.
    SQL> UPDATE KKQA_CLINIC_CD SET CLINIC_CD_EFFENDDT=REC_EFFENDDT;
    0 rows updated.
    A second attempt to rename another col, yeilds error:
    ALTER TABLE KKQA_CLINIC_CD SET CLINIC_CD_EFFDT=REC_EFFDT
    ERROR at line 1:
    ORA-02000: missing UNUSED keyword
    I just can't seem to find any meaningful examples or substance on this problem particularly ora-02000
    I have tried the "unused" keyword example, it basically deletes a col. Can someone help, I am thoroughly puzzled.

    Hi
    Renaming a column is not supported in 8i.
    Chris
    PS: the syntax is "ALTER TABLE <table name> RENAME COLUMN <old column name> TO <new column name>"

  • Rename columns

    Hi
    As input I use an Excel file with ONE worksheet and columns C1old, C2old, C3old...
    As output I use an Excel file with MORE worksheets W1, W2, W3...and columns W1_C1new, W1_C2new, W1_C3new...in worksheet W1, W2_C1new, W2_C2new, W2_C3new...in worksheet W2 and so on.
    In MS-SQL I have a table with 2 columns doing such mapping (renaming):
    C1old    W1_C1new
    C2old    W1_C2new
    C3old    W1_C3new
    C4old    W2_C1new
    C5old    W2_C2new
    How to implement it in SSIS?
    If it's too difficult I better write a macro (VBA) to simply rename columns and put them on the right worksheets according to the MS-SQL table.
    Thanks a lot!
    gec

    Hi Mecu9,
    Does the suggestions above solve your issue? If the issue persists, please post the detail information about your issue, so that we can make further analysis.
    Regards,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Rename column name

    Can i rename column name of a table. If so how to do it????

    before 9i
    Renaming a column in table:
    ==========================
    This is possible by updating the "name" column of the col$. To reflect this
    change in the system views, run catalog.sql and catproc.sql.
    Here is an example:
    SQL> create table test(
    x number,
    y varchar2(10),
    z varchar2(10));
    SQL> insert into test values (12,'Child','BLUE');
    SQL> insert into test values (34,'Mens','BROWN');
    If you wanted to rename column "x" as column "x1" then do the following.
    The first step is to identify the object number for the table (as SYS):
    SQL> select obj# from obj$
    where name='TEST' and owner#=9;
    OBJ#
    ======
    58217
    Now identify the column numbers for the table:
    SQL> select obj#, col#, name from col$ where obj#=58217;
    OBJ# COL# NAME
    58217 1 X
    58217 2 Y
    58217 3 Z
    To change the name, a simple update statement will suffice:
    update col$ set name='X1'
    where obj#=58217 and col#=1;
    To reflect the change in system views, run catalog and catproc (unix) eg:
    svrmgr> @$ORACLE_HOME/rdbms/admin/catalog
    svrmgr> @$ORACLE_HOME/rdbms/admin/catproc
    Now when a describe of the table is done:
    SQL> desc test;
    Name Null ? Type
    X1 NUMBER
    Y VARCHAR2(10)
    Z VARCHAR2(10)
    Similarly, selecting from the table and querying views such as
    DBA_TAB_COLUMNS shows the new column name.
    NOTE: Before changing column names, drop any indexes,
    foreign keys and primary constraints that might be on
    the column. These can be re-created later.

  • Rename column !!

    Can oracle 8i gives a facility to rename column ? How ?
    Thanks in Adv.

    Its a bit longer process but u can do it:
    SELECT obj#
    FROM sys.obj#
    WHERE name = '<your_table_name>';
    SELECT col#
    FROM sys.col$
    WHERE obj# = <obj# from the above query>
    AND name = '<column_name>';
    UPDATE sys.col$
    SET name = '<new_column_name>'
    WHERE obj# = <obj# used in the above query>
    AND col# = <col# from the above query>;
    It won't show the effect immediately. So use this:
    ALTER SYSTEM FLUSH SHARED_POOL;
    Now describe the table and find the new column name :)
    Hope this helps.
    -Rajeev

  • Renaming columns in 9i - sp

    Here is a stored proc we use to rename columns. It's not bulletproof, but it will get you started:
    create or replace procedure &&1.RenameColumn(uid IN varchar2,tablename IN varchar2,oldcolumn IN varchar2,newcolumn IN varchar2)
    as
         dt varchar2(106);
         dl number;
         dp number;
         ds number;
         nulls varchar2(1);
         dd long;
         buildstring varchar2(128);
         alteraddstring varchar2(256);
         alterdropstring varchar2(256);
         updatestring varchar2(128);
    begin
         SELECT data_type,data_length,data_precision,data_scale,nullable,data_default
         INTO dt,dl,dp,ds,nulls,dd
         FROM all_tab_columns
         WHERE UPPER(owner)=UPPER(uid) and UPPER(table_name)=UPPER(tablename)
         and UPPER(column_name)=UPPER(oldcolumn);
         CASE
         WHEN dt='CHAR'
              THEN
                   IF dl IS NOT NULL THEN
                        buildstring:=dt||' '||'('||dl||')';
                   ELSE
                        buildstring:=dt;
                   END IF;
         WHEN dt='DATE'
              THEN
                   buildstring:=dt;
         WHEN substr(dt,1,9)='TIMESTAMP'
              THEN
                   buildstring:=dt;
         WHEN dt='VARCHAR'
              THEN
                   IF dl IS NOT NULL THEN
                        buildstring:=dt||' '||'('||dl||')';
                   ELSE
                        buildstring:=dt;
                   END IF;
         WHEN dt='VARCHAR2'
              THEN
                   IF dl IS NOT NULL THEN
                        buildstring:=dt||' '||'('||dl||')';
                   ELSE
                        buildstring:=dt;
                   END IF;
         WHEN dt='NUMBER'
              THEN
                   buildstring:=dt;
                   IF dp IS NOT NULL THEN
                        buildstring:=buildstring||' '||'('||dp;
                        IF ds IS NOT NULL THEN
                             buildstring:=buildstring||','||ds;
                        END IF;
                        buildstring:=buildstring||')';
                   END IF;
         END CASE;
         IF nulls = 'N' THEN
              buildstring:=buildstring||' NOT NULL';
         END IF;
         IF dd is not null THEN
              IF dt='NUMBER' THEN
                   buildstring:=buildstring||' DEFAULT '||dd;
              ELSE
                   buildstring:=buildstring||' DEFAULT '''||dd||'''';
              END IF;
         END IF;
         dbms_output.put_line('String: ' || buildstring);
         alteraddstring:='alter table '||tablename||' add ('||newcolumn||' '||buildstring||')';
         dbms_output.put_line('AlterAddString: ' || alteraddstring);
         updatestring:='update '||tablename||' set '||newcolumn||'='||oldcolumn||'';
         dbms_output.put_line('UpdateString: ' || updatestring);
         alterdropstring:='alter table '||tablename||' drop column '||oldcolumn||'';
         dbms_output.put_line('DropString: ' || alterdropstring);
    EXECUTE IMMEDIATE alteraddstring;
    EXECUTE IMMEDIATE updatestring;
    EXECUTE IMMEDIATE alterdropstring;
    EXCEPTION
    WHEN OTHERS THEN
         dbms_output.put_line('ERROR executing renamecolumn'||SUBSTR(SQLERRM, 1, 100));
         rollback;
    end;

    Hi
    Renaming a column is not supported in 8i.
    Chris
    PS: the syntax is "ALTER TABLE <table name> RENAME COLUMN <old column name> TO <new column name>"

  • Renaming column giving error

    alter table tablename change oldcolumnnname to newcolumnname;
    but it has given partition or subpartition keyword is missing
    please suggest ..
    db: oracle 11g
    regards
    raj

    raj_fresher wrote:
    alter table mytabl rename column old_col to new_col
    this gives me the errorIt shouldn't, 11g too:
    SQL> alter table test_tab rename column x to y;
    Table altered.

  • Problem renaming column in Management Studio 2012

    After importing spreadsheet data with no column headings, I notes that SSMS provided column names like [Column 1] that contain a space. I think that is strange considering that SQL Server does not particularly like column names that include spaces. I don't
    like column names with spaces because when trying to create ad hoc queries just to analyze data, it becomes necessary to enclose those names in brackets...a real pain.
    So I began renaming columns using the Table Designer in SSMS. I had another spreadsheet open with the column names I wished to use. So I selected and copied from the spreadsheet and tried to paste the new name into the designer. That new name did not appear
    after the paste, so I copied again and pasted. Still no visible name in the designer. So I tried typing it in manually. After saving the change I see that new column name had become the name i wanted but repeated 3 times and concatenated? The column name I
    wanted was REGN_NUM. the saved name is REGN_NUM
    REGN_NUM
    REGN_NUM
    REGN_NUM.
    I just copied that new name from the Object Explorer and notice that line breaks are included. What is going on here?
    I just tried to rename that column again in the Object Explorer interface by right-clicking the column and clicking rename. I back-spaced out the visible letters and then pressed the delete key several times just in case there were trailing line feeds. During
    the renaming there looks to be the name I want in place before I click out of the rename input field. But low and behold, the quadruplicated name again appears. Huh? So I went to the next column, went through the renaming process by typing the new name in,
    and that one saved properly.
    Does anyone know what might be happening here?
    Thanks in advance for any replies.

    >After importing spreadsheet data with no column headings,
    How did you import it?  Use the SSIS Import/Export Wizard, column names can be assigned:
    http://www.sqlusa.com/bestpractices/ssis-wizard/
    Kalman Toth Database & OLAP Architect
    T-SQL Scripts at sqlusa.com
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Adding column in table having millions of records

    Hi,
    Oracle release :11.2.0.3
    Table A exists with millions of records. - has many indexes on it.
    Need to add one column which exists in table B with same no of records.
    Rowid is common join condition between table A and B to update this new column in A.
    Please advice the fastest way to update this column.
    Explain plan output for update query is :
    | Id  | Operation                                                   | Name                  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT                             |                       |   181M|  3287M|    95T  (1)|999:59:59 |
    |   1 |  UPDATE                                                | A                     |       |       |            |          |
    |   2 |   PX COORDINATOR                                |                       |       |       |            |          |
    |   3 |    PX SEND QC (RANDOM)                       | :TQ10000              |   181M|  3287M|   205K  (2)| 00:47:58 |
    |   4 |     PX BLOCK ITERATOR                           |                       |   181M|  3287M|   205K  (2)| 00:47:58 |
    |   5 |      TABLE ACCESS FULL                         | A                 |   181M|  3287M|   205K  (2)| 00:47:58 |
    PLAN_TABLE_OUTPUT
    |*  6 |   FILTER                                                    |                       |       |       |            |          |
    |*  7 |    TABLE ACCESS BY INDEX ROWID          | B        |   301K|    15M|   528K  (1)| 02:03:24 |
    |*  8 |     INDEX RANGE SCAN                              | SYS_C0073404          |    30M|       | 31081   (1)| 00:07:16 |
    Thanks in advance

    create table new_A as select *.A ,column_in_B from A,B where A.row_id=B.row_id;
    drop table A;
    rename new_A to A;
    No - that can't be right.
    You need to access the ROWID of table A; not some column in table A that is named 'row_id'. And that assumes, as PaulHorth asked, that table B DOES have a column named 'row_id' that contains the ROWID values of table A.
    Also you only posted the plan for the update statement: post the actual query that plan is based on.
    create table emp_rowid as
    select 'new_' || e.ename new_ename, e.rowid row_id from emp e
    where deptno = 20
    update /*+parallel (4) */ emp e
    set ename = (select new_ename from emp_rowid er
             where er.row_id = e.rowid)
    where rowid in (select row_id from emp_rowid)        
    select * from table(dbms_xplan.display_cursor())

  • RENAMING COLUMN NAME

    DEAR FRIENDS,
    I HAVE DATAS IN A COLUMN AND WANT TO RENAME IT WITHOUT CREATING ANOTHER TABLE AND INSERTING THE DATAS INTO IT. HOW TO DO THAT?

    SQL> desc emp
    Name                                      Null?    Type
    EMPNO                                     NOT NULL NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO                                             NUMBER(2)
    SQL> alter table emp rename column ename to employee_name ;
    Table altered.
    SQL> desc emp
    Name                                      Null?    Type
    EMPNO                                     NOT NULL NUMBER(4)
    EMPLOYEE_NAME                                      VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO                                             NUMBER(2)
    SQL>

  • Reg:How to delete the column in table control also from database table.

    Hi Experts,
    Once again thank u all for giving the responses.
    one more doubt is how to delete the columns of table control and also the record shold delete from ztable.
    With Regards,
    Saroja.P.

    Hi,
    If you want to delete the rows in the table control and simultaneously delete it from the database table, then you can implement a 'DELETE' functionality specific to your table control. Have a MARK field (you will find that in the screen attributes of the table control -> give a name for the MARK field, you will find an additional MARK column at the beginning of your table control). You can check whatever rows you want to delete from the table control, call the delete module.
    "This portion of code inside the LOOP...ENDLOOP.
    IF sy-ucomm eq 'F_DELETE'.
       gt_itab2-check = mark.  " Store the MARK field status into your internal table's correspoding field 'check'
      MODIFY gt_itab INDEX tabcontrol-current_line.
    ENDIF.
    iF sy-ucomm eq 'DELETE1'.
      DELETE gt_itab WHERE check eq 'X'. "Your internal table does not have rows that you want to delete
    ENDIF.
    Now you can modify your database table using the MODIFY statement.
    MODIFY ZDB FROM TABLE gt_itab.

Maybe you are looking for