Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if a dynamic table exists 1

Status
Not open for further replies.

whateveragain

Programmer
Apr 20, 2009
92
US
Can anyone please tell me how to write code to check if a dynamic table exists? The code below only works if table exists otherwise I get error. @preseldma is a dynamic table.

if exists(select * from dbo.sysobjects where id = object_id(N'[dbo].[@preseldma]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
print 'table exists'
END
 
In SQL Server 2005 and up:

if exists (select 1 from Information_Schema.Tables where
Table_Name = @Preseldma and table_schema = 'dbo')
print 'Table ' + @Preseldma + ' exists!'


PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top