views:

189

answers:

2

I would like to execute multiple statements on one line in SQL Server 2005. How do I do the following on a single line:


use master
go
sp_spaceused mytable

When I try use master; go; sp_spaceused mytable I get Incorrect syntax near 'go'.

When I try use master go sp_spaceused mytable I get Incorrect syntax near 'go'.

+2  A: 

You don't need go. Just use ;

Alexander Shirshov
+1  A: 
use master; sp_spaceused mytable;

should suffice. GO simply signals the end of a batch of Transact-SQL statements to the SQL Server utilities.

davek
I discovered that in addition to using the semi-colon, and not using `GO`, I also had to use the keyword `EXEC` in front of the stored procedure.
PP