How to remane a table or a table column (Oracle)

Configurare noua (How To)

Situatie

For changing the name of a table or only a column name of a table, you can :

Solutie

Pasi de urmat

Rename table:

ALTER TABLE table_name RENAME TO new_table_name;

 

Rename table:

ALTER TABLE table_name CHANGE COLUMN old_name TO new_name;

 

Sample :

CREATE TABLE my_table AS SELECT * FROM DBA_TABLES;
ALTER TABLE my_table RENAME COLUMN OWNER TO MY_OWNER;
ALTER TABLE my_table RENAME TO my_new_table;

 

Output :

SQL> CREATE TABLE my_table AS SELECT * FROM DBA_TABLES;
Table created.

sqlSQL> ALTER TABLE my_table RENAME COLUMN OWNER TO MY_OWNER;
Table altered.

SQL> ALTER TABLE my_table RENAME TO my_new_table;
Table altered.

SQL> desc my_new_table
Name Null? Type
----------------------------------------- -------- ----------------------------
MY_OWNER NOT NULL VARCHAR2(128) <---- here !?
TABLE_NAME NOT NULL VARCHAR2(128)
TABLESPACE_NAME VARCHAR2(30)
CLUSTER_NAME VARCHAR2(128)
IOT_NAME VARCHAR2(128)
STATUS VARCHAR2(8)
PCT_FREE NUMBER
PCT_USED NUMBER
INI_TRANS NUMBER

 

 

Tip solutie

Permanent

Voteaza

(2 din 7 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?