Testing for existance of a table

  • Is there a simple way to test for the existance of a table?

  • Here's one way:

    IF EXISTS

      (SELECT Name

       FROM <dbname>..SysObjects

       WHERE Name = '<tablename>')

    <rest of code>

    Replace <dbname> with the name of the database the table should be in.

    Replace <tablename> with the name of the table you are checking for.

    -SQLBill

  • Or use the Information_Schema.Tables view.. (instead of using sql server system tables)

  • Or try:

    IF OBJECTPROPERTY(OBJECT_ID(N'<YourTable>'), N'IsTable')
    BEGIN
         -- Your code
    END


    ----------------------------------------
    Pascal Dobrautz
    www.sqlassi.net

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply