How to check through TSQL if table exists | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

How to check through TSQL if table exists

Hi everyone, Can someone please tell me how to check if temporary table exists and based on that checking I can drop the table and re-create the same table. Thanx. Muneeb.
Depending on if you are refering to tables referenced by # or just a table you create for temporary use, modify which db you check in.
if exists (select * from sysobjects where id = object_id(N'[tablename]’) and OBJECTPROPERTY(id, N’IsTable’) = 1)
begin
–do whatever you want in here
end
if a table called #table then use this if exists (select * from tempdb..sysobjects where id = object_id(N'[#tablename]’) and OBJECTPROPERTY(id, N’IsTable’) = 1)
begin
–do whatever you want in here
end

Thanx Chris, this is what I was actually looking for. Thanx a lot. Muneeb.
]]>