重命名Oracle表

Gau*_*rty 2 sql oracle alter-table oracle11g table-rename

ALTER TABLE RENAME语句和RENAME TABLE语句之间有什么区别.

即,之间

Alter table old_table_name rename to new_table_name
Run Code Online (Sandbox Code Playgroud)

rename table old_table_name to new_table_name.
Run Code Online (Sandbox Code Playgroud)

Lal*_*r B 7

将表old_table_name重命名为new_table_name.

那种语法错了.没有table关键字要求.正确的语法是 -

rename old_table_name to new_table_name;

现在,让我们看看alter语句和简单rename语句之间的区别.

我有两个模式,SCOTTLALIT.

SQL> SHOW USER
USER is "SCOTT"
SQL>
SQL> create table t(id number);

Table created.

SQL> rename t to t_new;

Table renamed.

SQL> alter table t_new rename to t_newer;

Table altered.
Run Code Online (Sandbox Code Playgroud)

所以,这两个陈述都是一样的schema.

让我们连接到其他架构 -

SQL> SHOW USER
USER is "LALIT"
SQL>
SQL> create table t(id number);

Table created.

SQL> rename scott.t_newer to t_newest;
rename scott.t_newer to t_newest
       *
ERROR at line 1:
ORA-01765: specifying owner's name of the table is not allowed


SQL> alter table scott.t_newer rename to t_newest;

Table altered.
Run Code Online (Sandbox Code Playgroud)

所以,你看到了错误ORA-01765: specifying owner's name of the table is not allowed.这就是简单rename语句在其他模式对象上失败的地方.只有ALTER声明有效.