Cannot rename temporary table column

I created a global temp table like this -

CREATE TABLE ##BigTable
(Nos varchar(10) null)

Then try renaming the Nos column as follows:

EXEC sp_RENAME '##BigTable.Nos' , 'Numbers', 'COLUMN'

I got an error -

Either the parameter @objname is ambiguous or the 
claimed @objtype (COLUMN) is wrong.

Why can this happen and how can I solve the problem?



EXTRA not quite related to the question, but for reference.

I want to add this - I tried to create a global temp table using a completely name like this -

CREATE TABLE [NotMyTempDataBase].[dbo].[##BigTable]
(Nos varchar(10) null)

Then I tried to rename it with -

EXEC tempdb.sys.sp_rename N'[NotMyTempDataBase].[dbo].[##BigTable].Nos', 
N'Numbers', N'COLUMN';

Error - Qualified @oldname refers to a database other than the current database.

It is not right. I realized that the temporary table was created in the tempdb system database , although when creating it, a different database name is indicated.

use this instead -

CREATE TABLE [tempdb].[dbo].[##BigTable]
(Nos varchar(10) null)

- SQL: "tempdb" , tempdb.

EXEC tempdb.sys.sp_rename N'[tempdb].[dbo].[##BigTable].Nos', 
N'Numbers', N'COLUMN';
+6
2

, :

EXEC tempdb.sys.sp_rename N'##BigTable.Nos', N'Numbers', N'COLUMN';

#temp ( temp ##) tempdb, sp_rename.

:

  • temp ##? , concurrency ONE, ? , , ? , #local temp- , , #temp.

  • script? , . script , ? ?

+14

, . -

EXEC tempdb.sys.sp_rename N'#Tab1.Info', N'Numbers', N'COLUMN';
0

Source: https://habr.com/ru/post/1524574/


All Articles