Oracle - Column Rename
Transcript of Oracle - Column Rename
-
8/6/2019 Oracle - Column Rename
1/2
-
8/6/2019 Oracle - Column Rename
2/2
Renaming a Column Administration Tips
Copyright Howard Rogers 2001 10/17/2001 Page 2 of 2
CREATE TABLE NEWEMP (EMPLOYEE, JOB_DESC,SALARY) AS SELECT EMPNO, JOB,SAL FROM EMP;
Assuming you still want the table to be known as "EMP" and not "NEWEMP", you then have
to peform the following actions:
DROP TABLE EMP;
CREATE TABLE EMP AS SELECT * FROM NEWEMP;
DROP TABLE NEWEMP;
...but this is an expensive option: it requires two full tablescans (one of the original table
and one of the new version), the new table has no constraints on it, nor any indexes, and
all Users that had rights to EMP have no rights whatsoever to the newly-minted EMP, even
though it's name is the same (because its object number has nevertheless changed) -so you
have to re-create all constraints and indexes, and re-grant all permissions. You can make
the exercise rather less expensive by sticking the "nologging" clause in the CTAS command:
CREATE TABLE NEWEMP NOLOGGING AS SELECT ... FROM EMP;
...but that still doesn't get around the business of full tablescans being done all over the
place, and introduces the requirement to perform a new backup of EMP, since "nologging"
renders an object effectively unrecoverable until a new backup has been successfuly taken.
For how you pull the trick off in 9i, see the "How do I rename a column in 9i?" tip.