To Change Column Name In Oracle Table

Suppose we have an employee table like this :

SQL> SELECT * FROM EMPLOYEE;

    ID NAME            SALARY HIRE      EMAIL                  DEPT_ID MANAGER_ID     JOB_ID
------ ----------- ---------- --------- ------------------- ---------- ---------- ----------
     1 TEDY          11500000 05-JAN-09 tedy@apt.co.id               2                     3
     2 BUDY           2750000 01-SEP-02 budy@apt.co.id               1          1          3
     3 EDDY          49750000 09-MAY-03 eddy@apt.co.id               1          1          2
     4 LILIS          5200000 02-JUN-01 lilis@apt.co.id              2          1          4
     5 MANUS          1950000 29-OCT-10 manus@apt.co.id              3          2          6
     6 TONY           2300000 02-NOV-03 tony@apt.co.id               4          2          1
     7 YANNI          1500000 01-MAR-10 yanni@apt.co.id              3          2          5
 
7 rows selected.

SQL> 

In this example we want to change column ID to be EMPLOYEE_ID, the command to do that is like this :

SQL> ALTER TABLE EMPLOYEE RENAME COLUMN ID TO EMPLOYEE_ID;

Table altered.

SQL>

See that after run ALTER command above, now we have EMPLOYEE_ID column.

SQL> SELECT * FROM EMPLOYEE;

EMPLOYEE_ID NAME      SALARY     HIRE      EMAIL               DEPT_ID MANAGER_ID JOB_ID
----------- --------- ---------- --------- ------------------- ------- ---------- -------
          1 TEDY      11500000   05-JAN-09 tedy@apt.co.id            2                  3
          2 BUDY      2750000    01-SEP-02 budy@apt.co.id            1          1       3
          3 EDDY      49750000   09-MAY-03 eddy@apt.co.id            1          1       2
          4 LILIS     5200000    02-JUN-01 lilis@apt.co.id           2          1       4
          5 MANUS     1950000    29-OCT-10 manus@apt.co.id           3          2       6
          6 TONY      2300000    02-NOV-03 tony@apt.co.id            4          2       1
          7 YANNI     1500000    01-MAR-10 yanni@apt.co.id           3          2       5
 
7 rows selected.

SQL>

Leave a Reply