• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

GO ‘N’ Times,SQL执行同一个语句多次

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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/>


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
gomod使用私有gitlab群组的解决办法发布时间:2022-07-10
下一篇:
go语言日期时间格式化发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap