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.
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 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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With