Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropping a table in a database syntax

Status
Not open for further replies.

ccampbell

Programmer
Joined
Aug 16, 2001
Messages
201
Location
US
How can I check to see if a database table exists, and then if it does exist, drop it.
(ie
IF(TABLE TESTER EXISTS)
DROP TABLE TESTER
I am having a problem with the correct syntax. Could someone please help me with that.
 

Here is one way to accomplish that.

if exists
(select * from dbo.sysobjects
where id = object_id(N'[dbo].[tablename]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tablename]
GO
Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
THANKS TERRY,
ONCE AGAIN YOU COME TO THE RESCUE. THAT WORKED BEAUTIFULLY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top