T-SQL Tutorial

T-SQL RENAME


This article describes how to rename objects in a database.
The RENAME statement is part of DDL(Data Definition Language) statements.
Uses RENAME statement to modify name objects like: database, table, view, trigger, procedure, index, role.



RENAME DATABASE

To rename a SQL Server database name uses the system stored procedure SP_RENAMEDB or uses the T-SQL statement ALTER DATABASE.

EXEC SP_RENAMEDB N'database_name', N'new_database_name';
ALTER DATABASE database_name MODIFY NAME = new_database_name;


RENAME TABLE

The T-SQL system stored procedure SP_RENAME is used to change table name.

EXEC SP_RENAME 'table_name', 'new_table_name';

RENAME COLUMN

To rename a table column uses the system stored procedure SP_RENAME.

EXEC SP_RENAME 'Table_name.Column_name', 'New_Column_name', 'COLUMN';

RENAME VIEW

To rename a view in SQL Server database uses the command SP_RENAME.

EXEC SP_RENAME 'view_name', 'new_view_name';

RENAME TRIGGER

To rename a trigger is used the command SP_RENAME.

EXEC SP_RENAME 'trigger_name', 'new_trigger_name';

RENAME PROCEDURE

To rename a procedure is used the command SP_RENAME.

EXEC SP_RENAME 'procedure_name', 'new_procedure_name';