how to check for table !!!

  •  

             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 ...

  • Check for OBJECT_ID() in BOL.

  • If OBJECT_ID('TABLENAME') IS NOT NULL PRINT 'Table exists..'

    MohammedU
    Microsoft SQL Server MVP

  • 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

  • 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