Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2010-07-29 : 17:39:29
|
I have a problem with removing a previous table and establishing a new one of the same name without any trace of the previous iteration remaining. At present, I apply this:IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '#Q_TICKET') DROP TABLE #Q_TICKETSELECT [event_id], [section_id], [row_id], [seat_num]INTO [#Q_TICKET]FROM ALPHA_TXwhere event_id = "RU12"GOHowever, I always get this:Server: Msg 2714, Level 16, State 6, Line 8There is already an object named '#Q_TICKET' in the database.(10 row(s) affected)DELETE TABLE won't work and TRUNCATE TABLE only leaves a ghostie.How can I simply erase the previous iteration an create anew?Thanks... Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL & VB obviously! |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-07-29 : 18:19:52
|
temp tables aren't in INFORMATION_SCHEMA.TABLESif you need to test for the existence of the #temp table before dropping it, do it like thisif object_id('tempdb..#Q_TICKET') is not nulldrop table #Q_TICKET Semper Fi brother! |
 |
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2010-07-29 : 18:30:38
|
The Gunny thanks you, Marine!BUT.....what if it isn't a TEMP table?Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL & VB obviously! |
 |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-07-29 : 23:05:12
|
Gunny, if it starts with a # then it is a temp table. if it really isn't a temp table then your code will work.so will mine, if u remove the tempdb referenceif object_id('yourTable') is not null... |
 |
|
|
|
|
|
|