Adam K Dean

Check if temp table exists in SQL

Published on 14 October 2015 at 16:48 by Adam

I'm going to start posting some SQL snippets, either things I learn day to day or things that I've had sat around for years.

Today's is a checking if a temp table exists (and then dropping it.)

IF OBJECT_ID('Tempdb..#tablename') IS NOT NULL
BEGIN
    -- do something here, like say, drop that table?
    DROP TABLE #tablename;
END


This post was first published on 14 October 2015 at 16:48. It was filed under archive with tags sql.