January 21, 2007 at 10:49 pm
I want to check a table whether that particular table is there in the database or not. How to write a query that i get the answer that whether the particular table is in the database or not. THERE SHOULD NOT BE ANY WARNING OR ERROR I WANT. i just want to check the availability of table and it should give me the result no the error... can anyone tell me how to accomplish this one...
in advance thanks ...
January 21, 2007 at 11:36 pm
Check for OBJECT_ID() in BOL.
January 22, 2007 at 12:05 am
If OBJECT_ID('TABLENAME') IS NOT NULL PRINT 'Table exists..'
MohammedU
Microsoft SQL Server MVP
January 22, 2007 at 2:23 am
Beware, because if you have a stored procedure or other object called TABLENAME, you will still get the "Table Exists" message. One way of being sure is like this:
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE')
PRINT 'Table exists'
John
January 22, 2007 at 10:32 am
Should be :
If OBJECT_ID('TABLENAME','U') IS NOT NULL PRINT 'Table exists..'
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply