T-SQL Tutorial

T-SQL sp_rename


On Transact SQL language the sp_rename is part of Database Engine Stored Procedures and rename the name of an object (table, index, column or alias data type) in the current database. Returns 0 for success or error message for failure.

sp_rename syntax:

sp_rename [ @objname = 'Object name' ] , [ @newname = 'New object name' ] [ , [ @objtype = 'Object type' ] ] ;





Rename a table:

USE model;
GO
EXEC sp_rename 'Departments', 'test';
GO

Rename a column:

USE model;
GO EXEC sp_rename 'my_table.b', 'c', 'COLUMN';
GO