SQL Server 2005中的一行上的多个命令

问题描述 投票:16回答:3

我想在SQL Server 2005中的一行上执行多条语句。如何在一行上执行以下操作:


use master
go
sp_spaceused mytable

[当我尝试use master; go; sp_spaceused mytable时,我会得到Incorrect syntax near 'go'

[当我尝试use master go sp_spaceused mytable时,我会得到Incorrect syntax near 'go'

sql-server sql-server-2005
3个回答
16
投票
use master; sp_spaceused mytable;

应足够。 GO只是signals the end of a batch of Transact-SQL statements to the SQL Server utilities


8
投票

您不需要GO。只需使用;


0
投票

到目前为止提供的答案是不正确的。如果行必须在单独的批处理中,则不能将行与分号合并。试试这个:

DECLARE @x int; DECLARE @x int;
© www.soinside.com 2019 - 2024. All rights reserved.