views:

4614

answers:

5

What is the syntax to rename a table or view in Oracle?

+12  A: 
ALTER TABLE mytable RENAME TO othertable

In Oracle 10g also:

RENAME mytable TO othertable
Quassnoi
+2  A: 

In order to rename a table in a different schema, try:

ALTER TABLE owner.mytable RENAME TO othertable;

The rename command (as in "rename mytable to othertable") only supports renaming a table in the same schema.

Pop
+4  A: 

To rename a table you can use:

RENAME mytable TO othertable;

or

ALTER TABLE mytable RENAME TO othertable;

or, if owned by another schema:

ALTER TABLE owner.mytable RENAME TO othertable;

Interestingly, ALTER VIEW does not support renaming a view. You can, however:

RENAME myview TO otherview;

The RENAME command works for tables, views, sequences and private synonyms, for your own schema only.

If the view is not in your schema, you can recompile the view with the new name and then drop the old view.

(tested in Oracle 10g)

Jeffrey Kemp
+1  A: 

One can rename indexes the same way

alter index *owner.index_name* rename to *new_name*;

Maurício
A: 

alter index*owner.index_name*rename to *new_name*;

shiva malik