3

ALTER TABLE RENAME 语句和 RENAME TABLE 语句有什么区别。

即,介于

Alter table old_table_name rename to new_table_name

rename table old_table_name to new_table_name.
4

1 回答 1

12

将表 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.

因此,这两个语句都适用于相同的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.

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

于 2015-01-08T11:17:24.593 回答