June 23, 2010 at 6:14 pm
Is it possible to rename a temp table from #temp to #temp1?
June 23, 2010 at 7:06 pm
I don't think it is - but I have to ask why you would want to? What problem are you trying to solve by doing this?
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
June 23, 2010 at 7:06 pm
I don't believe so. Not in any forthright manner, anyway. Perhaps if you explained why you need to do such a thing, we could suggest an alternative.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 24, 2010 at 3:39 am
Jeff Moden (6/23/2010)
I don't believe so. Not in any forthright manner, anyway. Perhaps if you explained why you need to do such a thing, we could suggest an alternative.
I guess one of alternative could be this:
SELECT * INTO #TableNewName FROM #Table
DROP TABLE #Table
Why would you want to do it?
June 24, 2010 at 5:29 am
The code in the sys.sp_rename stored procedure contains an explicit check for temporary tables, and raises an error.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
June 24, 2010 at 7:12 am
Eugene Elutin (6/24/2010)
Jeff Moden (6/23/2010)
I don't believe so. Not in any forthright manner, anyway. Perhaps if you explained why you need to do such a thing, we could suggest an alternative.I guess one of alternative could be this:
SELECT * INTO #TableNewName FROM #Table
DROP TABLE #Table
Now... try reusing the temp table name with different column names in the same stored procedure.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 24, 2010 at 7:34 am
Jeff Moden (6/24/2010)
Eugene Elutin (6/24/2010)
Jeff Moden (6/23/2010)
I don't believe so. Not in any forthright manner, anyway. Perhaps if you explained why you need to do such a thing, we could suggest an alternative.I guess one of alternative could be this:
SELECT * INTO #TableNewName FROM #Table
DROP TABLE #Table
Now... try reusing the temp table name with different column names in the same stored procedure.
Why with different column names? I think it will not work even with the same ones! But it was not required in the first place 😀
I have added DROP TABLE just to ensure that table1 cannot be used after creating the new one.
I guess, the main issue we have in this question thread is trying to understand the reason why renaming of table would be required at all. Isn't it?
I guess another thread (http://www.sqlservercentral.com/Forums/Topic942137-392-1.aspx, about generating temp table dynamicaly with diff. columns in dynamic sql based on input...) put some light into this one. But,
without better understanding of what Mister Ken is trying to achieve as a result, it will be hard to advise on both cases. So far I am not even sure If he even needs temp tables at all.
June 24, 2010 at 7:52 am
Eugene Elutin (6/24/2010)
Jeff Moden (6/24/2010)
Eugene Elutin (6/24/2010)
Jeff Moden (6/23/2010)
I don't believe so. Not in any forthright manner, anyway. Perhaps if you explained why you need to do such a thing, we could suggest an alternative.I guess one of alternative could be this:
SELECT * INTO #TableNewName FROM #Table
DROP TABLE #Table
Now... try reusing the temp table name with different column names in the same stored procedure.
Why with different column names? I think it will not work even with the same ones! But it was not required in the first place 😀
I have added DROP TABLE just to ensure that table1 cannot be used after creating the new one.
I guess, the main issue we have in this question thread is trying to understand the reason why renaming of table would be required at all. Isn't it?
I guess another thread (http://www.sqlservercentral.com/Forums/Topic942137-392-1.aspx, about generating temp table dynamicaly with diff. columns in dynamic sql based on input...) put some light into this one. But,
without better understanding of what Mister Ken is trying to achieve as a result, it will be hard to advise on both cases. So far I am not even sure If he even needs temp tables at all.
Correct and exactly why I've not attempted to offer an alternative, yet. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply