title: SQL Server : check if two tables exist
body: <p>Is this correct if I am trying to delete and create a new table when only and only both of these tables exist? The table B is coming from another SQL Server (same version of SQL Server 2012)</p>
  
  <pre><code>IF EXISTS ((SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[TableA]')
             AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
             INTERSECT
             (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[AnotherServer].Database.dbo.TableB')
             AND OBJECTPROPERTY(id, N'IsUserTable') = 1))
  BEGIN
      DROP TABLE TableA
  
      SELECT *
      INTO TableA
      FROM [AnotherServer].Database.dbo.TableB
  END
  </code></pre>