How To Rename a Column in an Existing Table?
Submitted by: AdministratorLet's say you have an existing with an existing column, but you don't like the name of that column, can you rename that column name? The answer is yes. You can use the ALTER TABLE ... RENAME COLUMN statement to do this. See the following SQL script:
SQL> CREATE TABLE emp_dept_90
2 AS SELECT * FROM employees WHERE department_id=90;
Table created.
SQL> SELECT first_name, last_name FROM emp_dept_90;
<pre>FIRST_NAME LAST_NAME
-------------------- -------------------------
Steven King
Neena Kochhar
Lex De Haan </pre>
SQL> ALTER TABLE emp_dept_90 RENAME COLUMN first_name
2 TO fname;
Table altered.
SQL> SELECT fname, last_name FROM emp_dept_90;
<pre>FNAME LAST_NAME
-------------------- -------------------------
Steven King
Neena Kochhar
Lex De Haan</pre>
As you can see the column "first_name" is nicely changed to "fname".
Submitted by: Administrator
SQL> CREATE TABLE emp_dept_90
2 AS SELECT * FROM employees WHERE department_id=90;
Table created.
SQL> SELECT first_name, last_name FROM emp_dept_90;
<pre>FIRST_NAME LAST_NAME
-------------------- -------------------------
Steven King
Neena Kochhar
Lex De Haan </pre>
SQL> ALTER TABLE emp_dept_90 RENAME COLUMN first_name
2 TO fname;
Table altered.
SQL> SELECT fname, last_name FROM emp_dept_90;
<pre>FNAME LAST_NAME
-------------------- -------------------------
Steven King
Neena Kochhar
Lex De Haan</pre>
As you can see the column "first_name" is nicely changed to "fname".
Submitted by: Administrator
Read Online Oracle Database Job Interview Questions And Answers
Top Oracle Database Questions
☺ | What Happens to Indexes If You Drop a Table? |
☺ | How To Recover a Dropped Table in Oracle? |
☺ | How To Create Tables for ODBC Connection Testing? |
☺ | How To Retrieve Data from an Explicit Cursor? |
☺ | What Is a Table Index in Oracle? |
Top DB Oracle Categories
☺ | Oracle PL-SQL Interview Questions. |
☺ | Oracle DBA Interview Questions. |
☺ | Oracle D2K Interview Questions. |
☺ | OCI Interview Questions. |
☺ | Oracle RMAN Interview Questions. |