Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error renaming a temporary table

Is it possible to rename a temporary table?

create table #t (id integer);
execute tempdb.sys.sp_rename '#t', '#s';

An invalid parameter or option was specified for procedure 'sys.sp_rename'

The proposed solution by @Michel, inserting into another temp table and dropping the original, works but I guess how expensive it is.

like image 883
Clodoaldo Neto Avatar asked Nov 13 '12 11:11

Clodoaldo Neto


People also ask

How do you name a temporary table in SQL?

The global temporary tables are created using the CREATE TABLE statement and their names must be prefixed with the double hashtag (##) sign. These tables can be accessed by all other sessions, unlike local ones.

How do I rename a column in a temp table in SQL Server?

How to rename column name in Sql Server. Many times we come across a scenario where we need to rename / change the existing table column name. We can use the SP_RENAME system stored to change/rename the table column name.

How do you change the name of a table from Oldname to Newname?

To rename a table in Oracle SQL, use the ALTER TABLE statement, in the same way as MySQL and PostgreSQL: ALTER TABLE old_name RENAME TO new_name; You simply add in your current table name and the new table name and run the command. There's no need to specify the schema name.


1 Answers

Tempdb doesn't have the sp_rename procedure. What you could do is to create a new temptable with the contents of your old one

Something like this

select * into #NewName from #OldName
drop table #OldName
like image 56
Michel Feldheim Avatar answered Oct 20 '22 08:10

Michel Feldheim