How do I delete a temp table and ensure that its only for the current @@spid.
IF EXISTS
(
SELECT *
FROM tempdb.dbo.sysobjects
WHERE ID = OBJECT_ID(N'tempdb..#tmp')
)
BEGIN
DROP TABLE #tmp
END
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A local #temp table is, by definition, only for the current
spidsession_id– so your query already does what you’re asking. This is probably a bit simpler though:But what is the purpose of explicitly dropping this temp table? You know the parser won’t let you create another one with the same name in the same batch, right?