How to check if the global Temporary table exists in SQL server, if yes then delete that global temporary table?
I am trying to execute this:
IF OBJECT_ID('##Table', 'U') IS NOT NULL
DROP TABLE ##Table
...but it is not working.
To check the presence of temp table and delete it
IF OBJECT_ID('tempdb..##Table' , 'U') IS NOT NULL
drop TABLE ##Table
You can detect temp table presence with
IF OBJECT_ID('tempdb.dbo.##Table', 'U') IS NOT NULL
and, surprisingly to me, you can drop it from any connection with
DROP TABLE ##Table
However, I can't help but think that doing so would be a bad idea, since presumably the connection/user who created it might still be using it...
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