Not.
If you use this from a database other than tempdb
, you get
An item named '#tbl_tmp' cannot be found in the current database ....
Which is not surprising, since all data pages, etc. are in tempdb
data files, so you cannot rename it to suddenly become a permanent table in another database.
If you use this from tempdb
, you get
An invalid parameter or parameter was specified for the 'Sys.sp_rename' procedure.
If you execute EXEC sp_helptext sp_rename
and look at the definition corresponding to a bit of code prohibiting this,
-------------------------------------------------------------------------- -------------------- PHASE 32: Temporay Table Isssue ------------------- -------------------------------------------------------------------------- -- Disallow renaming object to or from a temp name (starts with #) if (@objtype = 'object' AND (substring(@newname,1,1) = N'#' OR substring(object_name(@objid),1,1) = N'#')) begin COMMIT TRANSACTION raiserror(15600,-1,-1, 'sys.sp_rename') return 1 end
Why don't you just create a persistent table first and then rename it?
source share