Skip Headers
Oracle® Database SQL Language Reference
11g Release 2 (11.2)

Part Number E26088-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub
SQLRF01608

RENAME

Purpose

Caution:

You cannot roll back a RENAME statement.

Use the RENAME statement to rename a table, view, sequence, or private synonym.

Prerequisites

The object must be in your own schema.

Syntax

SQLRF55174rename::=

Description of rename.gif follows
Description of the illustration rename.gif

Semantics

SQLRF55175old_name

Specify the name of an existing table, view, sequence, or private synonym.

SQLRF55176new_name

Specify the new name to be given to the existing object. The new name must not already be used by another schema object in the same namespace and must follow the rules for naming schema objects.

SQLRF55177Restrictions on Renaming Objects Renaming objects is subject to the following restrictions:

Example

SQLRF55178Renaming a Database Object: Example The following example uses a copy of the sample table hr.departments. To change the name of table departments_new to emp_departments, issue the following statement:

RENAME departments_new TO emp_departments;

You cannot use this statement directly to rename columns. However, you can rename a column using the ALTER TABLE ... rename_column_clause.

Another way to rename a column is to use the RENAME statement together with the CREATE TABLE statement with AS subquery. This method is useful if you are changing the structure of a table rather than only renaming a column. The following statements re-create the sample table hr.job_history, renaming a column from department_id to dept_id:

CREATE TABLE temporary 
   (employee_id, start_date, end_date, job_id, dept_id) 
AS SELECT 
     employee_id, start_date, end_date, job_id, department_id
FROM job_history; 

DROP TABLE job_history; 

RENAME temporary TO job_history; 

Any integrity constraints defined on table job_history will be lost in the preceding example. You will have to redefine them on the new job_history table using an ALTER TABLE statement.

Reader Comment

   

Comments, corrections, and suggestions are forwarded to authors every week. By submitting, you confirm you agree to the terms and conditions. Use the OTN forums for product questions. For support or consulting, file a service request through My Oracle Support.

Hide Navigation

Quick Lookup

Database Library · Master Index · Master Glossary · Book List · Data Dictionary · SQL Keywords · Initialization Parameters · Advanced Search · Error Messages

Main Categories

This Document

New and changed documents:
RSS Feed HTML RSS Feed PDF