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

私は 2 つのスキーマを持っていSCOTTますLALIT

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 に答える