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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758200742, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL-Server/administration/schemas/sys/objects/stored-procedures/sp_rename/index(86): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78