I would like to execute multiple statements on one line in SQL Server 2005. How do I do the following on a single line:
我想在SQL Server 2005中的一行上执行多个语句。如何在一行上执行以下操作:
use master
go
sp_spaceused mytable
When I try use master; go; sp_spaceused mytable
I get Incorrect syntax near 'go'
.
当我尝试使用主人;走; sp_spaceused mytable我在'go'附近得到错误的语法。
When I try use master go sp_spaceused mytable
I get Incorrect syntax near 'go'
.
当我尝试使用master go sp_spaceused mytable时,我在'go'附近得到错误的语法。
3 个解决方案
#1
13
use master; sp_spaceused mytable;
should suffice. GO
simply signals the end of a batch of Transact-SQL statements to the SQL Server utilities.
应该足够了。 GO只是将一批Transact-SQL语句的结尾发送给SQL Server实用程序。
#2
8
You don't need go. Just use ;
你不需要去。只是用;
#3
1
The answers provided thus far are incorrect. It does not work to combine lines with a semi-colon if the lines must be in a separate batch. Try this one:
到目前为止提供的答案是不正确的。如果行必须在单独的批处理中,则不能将行与分号组合。试试这个:
DECLARE @x int; DECLARE @x int;
#1
13
use master; sp_spaceused mytable;
should suffice. GO
simply signals the end of a batch of Transact-SQL statements to the SQL Server utilities.
应该足够了。 GO只是将一批Transact-SQL语句的结尾发送给SQL Server实用程序。
#2
8
You don't need go. Just use ;
你不需要去。只是用;
#3
1
The answers provided thus far are incorrect. It does not work to combine lines with a semi-colon if the lines must be in a separate batch. Try this one:
到目前为止提供的答案是不正确的。如果行必须在单独的批处理中,则不能将行与分号组合。试试这个:
DECLARE @x int; DECLARE @x int;