Check if table exists

  • You haven't mentioned what version of SQL. If 2005 or above, this will work. If 2000, replace sys.tables with sysobjects and add an extra filter for xtype = 'U'

    IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'Table to be inserted into'

    BEGIN

    -- do stuff

    END

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing post 1 (of 2 total)

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