code_junkie

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

Nov 12th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. IF OBJECT_ID('temp_ARCHIVE_RECORD_COUNTS') IS NOT NULL
  2. DROP TABLE temp_ARCHIVE_RECORD_COUNTS
  3.  
  4. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TableName]') AND type in (N'U'))
  5. DROP TABLE TableName;
  6. GO
  7.  
  8. if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME='MyTable') begin
  9. drop table MyTable
  10. end
  11.  
  12. IF EXISTS( SELECT * FROM dbo.sysobjects where id = object_id(N'TABLENAME') AND OBJECTPROPERTY(id, N'IsTable') = 1)
  13. BEGIN
  14. DROP TABLE TABLENAME
  15. END
Add Comment
Please, Sign In to add comment