adamkdean

software engineering

Check if temp table exists in SQL

By Adam K Dean on

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