Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Why this error?

Author  Topic 

acesover
Starting Member

15 Posts

Posted - 2014-04-11 : 21:12:20
I get the following errors when I run the block of code below, but if I run the EXEC statement on it's own, no error. Also, the database does get deleted. Any ideas? Thanks.

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'WSS_Content_1'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'END

IF EXISTS( SELECT name FROM master.sys.databases WHERE NAME = N'WSS_CONTENT_1')
BEGIN
EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'WSS_Content_1'
GO
USE [master]
GO
DROP DATABASE [WSS_Content_1]
GO
END

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-04-12 : 04:58:34
You can't wrap GO in T-SQL code. They are batch separators.
IF EXISTS(SELECT * FROM master.sys.databases WHERE NAME = N'WSS_CONTENT_1')
BEGIN
EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'WSS_Content_1';
EXEC ('USE [master]; DROP DATABASE [WSS_Content_1];');
END



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

acesover
Starting Member

15 Posts

Posted - 2014-04-14 : 11:10:45
That worked. Thanks SwePeso.

Dan
Go to Top of Page
   

- Advertisement -