Home >Database >Oracle >How to modify the name of a table in Oracle

How to modify the name of a table in Oracle

青灯夜游
青灯夜游Original
2021-12-24 14:40:0938523browse

How to modify the table name in oracle: 1. Use the "ALTER TABLE table_name RENAME TO new_table_name;" statement; 2. Use the "RENAME table_name TO new_table_name;" statement.

How to modify the name of a table in Oracle

The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.

oracle modifies the name of the table (renames the table)

For an existing table, you can also modify its name. There are two syntax forms for renaming a table:

  • One is to use the ALTER TABLE statement, the syntax is as follows:

ALTER TABLE table_name RENAME TO new_table_name;
  • The other is to use the RENAME statement directly, the syntax is as follows:

RENAME table_name TO new_table_name;

Expand knowledge:

  • Modify the name of the column

The syntax for modifying the name of the column in the table is as follows:

ALTER TABLE table_name RENAME COLUMN column_name TO new_column_name;

For example, change the name of the birthday column in the person table to age, as follows:

SQL> ALTER TABLE person RENAME COLUMN birthday TO age;

The table has been changed.

  • Modify the data type of a column

The syntax for modifying the data type of a column in a table is as follows:

ALTER TABLE table_name MODIFY column_name new_data_type;

For example, change the data type of the age column in the person table to NUMBER(4), as follows:

SQL> ALTER TABLE person MODIFY age NUMBER(4);

The table has been changed.

Note: The alter ... modify used here should be distinguished from the alter ... add used to modify Oracle's table-level constraints. Don't get confused.

Recommended tutorial: "Oracle Tutorial"

The above is the detailed content of How to modify the name of a table in Oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn