Search notes:

SQL Server: sp_rename

sp_rename can be used to change the name of tables, views, stored procedures, columns (and other objects?)

Rename a table

--
-- Create a table
--
create table spelled_rwongly (a int);

--
-- Manipulate values in table
--
insert into spelled_rwongly values (42);

--
-- Decide to rename table
--
exec sp_rename 'spelled_rwongly', 'spelled_correctly';
--
--  Caution: Changing any part of an object name could break scripts and stored procedures.
--

--
--  Use renamed table
--
select * from  spelled_correctly;
drop     table spelled_correctly;
Github repository about-MSSQL, path: /administration/schemas/sys/objects/stored-procedures/sp_rename/rename-table.sql

Rename a colum

The name of a column is changed analogously:
create table some_table (
   phoo  integer,
   bar   varchar(10),
   bats  date
);
go

exec sp_rename 'some_table.phoo', 'foo';
go

exec sp_columns 'some_table'
go
Github repository about-MSSQL, path: /administration/schemas/sys/objects/stored-procedures/sp_rename/rename-column.sql
Note that computed columns cannot be renamed.

Misc

Changing the name of views, functions, stored procedures or triggers with sp_rename does not change the corresponding object name in the sys.sys_modules catalog view.

Index