SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Why this error?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

acesover
Starting Member

15 Posts

Posted - 04/11/2014 :  21:12:20  Show Profile  Reply with Quote
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

Sweden
30265 Posts

Posted - 04/12/2014 :  04:58:34  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 - 04/14/2014 :  11:10:45  Show Profile  Reply with Quote
That worked. Thanks SwePeso.

Dan
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000