GO ‘N’ Times,SQL执行同一个语句多次
2013-07-25 15:31
549 查看
GO (Transact-SQL)
语法
GO [count]
参数
count
为一个正整数。 GO 之前的批处理将执行指定的次数。
源文档 <http://msdn.microsoft.com/zh-cn/library/ms188037.aspx>
GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor.
SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of SQL Server. The current batch of statements is composed of all statements entered since the last GO, or since the start of the ad hoc session or script if this is the first GO.
A Transact-SQL statement cannot occupy the same line as a GO command. However, the line can contain comments.
The scope of local (user-defined) variables is limited to a batch, and cannot be referenced after a GO command.
---- GO后面,不可以使用参数,只能硬编码,GO一个正整数次数。
源文档 <http://msdn.microsoft.com/zh-cn/library/ms188037.aspx>
下面是一个例子:
One unbelievable tip for the day for T-SQL users. What a “GO” statement do in T-SQL.
By definition it is a batch separator. It will run a batch and commit it. But along with that it also accepts one parameter which tells the SQL engine basically how many times to do the job.
For Example,
SELECT * FROM sys.objects;
GO 3
It will show the output THREE times :)
Next Example,
CREATE TABLE #ProductTable
(
ID INT IDENTITY (1, 1),
Name VARCHAR (50)
);
GO
INSERT INTO #ProductTable (Name)
VALUES ('Office XP');
GO 3
SELECT *
FROM #ProductTable;
OUTPUT
源文档 <http://www.sqllion.com/2011/09/go-n-times/>
语法
GO [count]
参数
count
为一个正整数。 GO 之前的批处理将执行指定的次数。
源文档 <http://msdn.microsoft.com/zh-cn/library/ms188037.aspx>
GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor.
SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of SQL Server. The current batch of statements is composed of all statements entered since the last GO, or since the start of the ad hoc session or script if this is the first GO.
A Transact-SQL statement cannot occupy the same line as a GO command. However, the line can contain comments.
The scope of local (user-defined) variables is limited to a batch, and cannot be referenced after a GO command.
---- GO后面,不可以使用参数,只能硬编码,GO一个正整数次数。
源文档 <http://msdn.microsoft.com/zh-cn/library/ms188037.aspx>
下面是一个例子:
One unbelievable tip for the day for T-SQL users. What a “GO” statement do in T-SQL.
By definition it is a batch separator. It will run a batch and commit it. But along with that it also accepts one parameter which tells the SQL engine basically how many times to do the job.
For Example,
SELECT * FROM sys.objects;
GO 3
It will show the output THREE times :)
Next Example,
CREATE TABLE #ProductTable
(
ID INT IDENTITY (1, 1),
Name VARCHAR (50)
);
GO
INSERT INTO #ProductTable (Name)
VALUES ('Office XP');
GO 3
SELECT *
FROM #ProductTable;
OUTPUT
源文档 <http://www.sqllion.com/2011/09/go-n-times/>
相关文章推荐
- 使用GO将SQL语句重复执行多次
- 一个Web报表项目的性能分析和优化实践(一):小试牛刀,统一显示SQL语句执行时间
- C#中 一次执行多条带GO的sql语句
- 同一个SQL语句 会由于表的数据(量、和值个数不同等)变化而执行不同的执行计划
- 在C#中执行带有GO的批量sql语句
- 在数据库中查看一个sql语句的执行时间和SP2-0027错误
- mybatis一个select标签执行多个sql语句
- 一个sql语句执行顺序
- DBA手记 - optimizer_mode影响一个SQL语句是否可以执行
- 执行带一个存储过程参数的的SQL语句。
- %EXCEUTE在一个SQL Action里执行多条SQL语句
- 在oracle 数据库中查看一个sql语句的执行时间和SP2-0027错误
- [置顶] 一个Web报表项目的性能分析和优化实践(一):小试牛刀,统一显示SQL语句执行时间
- .net 执行sql包含go语句的处理
- 如何在mybatis中一个insert,delete,update中执行多条SQL语句
- 探讨:Oracle数据库查看一个进程是如何执行相关的实际SQL语句
- DBA手记-optimizer_mode影响一个SQL语句是否可以执行
- 一个简单的存储过程(实现事务执行两个sql语句,修改可实现执行更多条sql语句)
- 如何查看,当运行一个hibernate 方法后到底执行了哪些SQL语句
- C#中 如何执行带GO的sql 语句