Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I drop a table if it exists in SQL Server 2000?

Tags:

I have a DTS package that drops a table then creates it and populates it but sometimes something happens and the package fails after the drop table. If it's rerun it fails cuz the table hasn't been created yet.

Is there something like "if exists" for SQLServer 2000 like in MySQL?

thanks.

like image 431
Keng Avatar asked Oct 30 '08 18:10

Keng


People also ask

Can we drop a table which is in reference with another table?

Remarks. DROP TABLE cannot be used to drop a table that is referenced by a FOREIGN KEY constraint. The referencing FOREIGN KEY constraint or the referencing table must first be dropped.


1 Answers

Or quicker:

IF OBJECT_ID('temp_ARCHIVE_RECORD_COUNTS') IS NOT NULL  
  DROP TABLE temp_ARCHIVE_RECORD_COUNTS  
  • OBJECT_ID - MSDN Reference - SQL Server 2000
  • OBJECT_ID - MSDN Reference - SQL Server 2008
like image 153
Bob Probst Avatar answered Sep 18 '22 06:09

Bob Probst