Does A Table Exist In A Database

I need a query that will check to see if a table ( PaymentType ) exist in a database.  If it does exist the query needs to return a 1 if the table does not exist return a 0.

Any help in creating this query will be appreciated.
LVL 2
Phil ChapmanAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
computerstreberConnect With a Mentor Commented:
Here you go
DECLARE @exist INT

SET @exist = 0

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PaymentType]') AND type in (N'U'))
BEGIN
     SET @exist = 1
END

Open in new window

0
 
TripyreCommented:
IF OBJECT_ID ('AdventureWorks.dbo.AWBuildVersion','U') IS NOT NULL
Print 'Table Exists'
ELSE
Print 'Table Does Not Exists'

where 'AdventureWorks.dbo.AWBuildVersion' is the object name and 'U' is the object type which represents a table

http://www.sqlservercurry.com/2007/12/check-if-database-or-table-exists-using.html
0
 
Phil ChapmanAuthor Commented:
Thanks
0
All Courses

From novice to tech pro — start learning today.