RENAME

RENAME is a Data Definition Language (DDL) command in SQL used to change the name of a table or a column. This statement is used when a user intends to modify the existing name to a new specified name. It aids in enhancing readability and understanding of the schema structure for a user. This command varies across different SQL dialects.

Example

ALTER TABLE employees
RENAME TO team;

Output

Query OK, 0 rows affected (0.02 sec)

Explanation

This code renames the “employees” table to “team”. The output “Query OK, 0 rows affected (0.02 sec)” signifies successful execution of the code.

Example

EXEC sp_rename 'old_table_name', 'new_table_name'

Output

Caution: Changing any part of an object name could break scripts and stored procedures.

Explanation

sp_rename is a stored procedure that allows you to rename database objects like tables, columns, and indexes. The above command renames a table named old_table_name to new_table_name. Although SQL Server issues a warning, the rename operation still completes successfully.

Example

RENAME TABLE old_table TO new_table;

Output

This command does not provide any output. It performs the operation silently.

Explanation

In the given example, RENAME is the SQL command used to change the name of old_table to new_table. If the operation is successful, Oracle doesn’t provide any output. If unsuccessful, Oracle will output an error message.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.