DEV Community

Cover image for Check if temp table exists in SQL
Adam K Dean
Adam K Dean

Posted on

Check if temp table exists in SQL

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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)