码迷,mamicode.com
首页 > 其他好文 > 详细

begin--end和go

时间:2014-12-26 00:58:11      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:

GO is like the end of a script.

You could have multiple CREATE TABLE statements, separated by GO. It‘s a way of isolating one part of the script from another, but submitting it all in one block.

 

BEGIN and END are just like { and } in C/++/#, Java, etc.

They bound a logical block of code. I tend to use BEGIN and END at the start and end of a stored procedure, but it‘s not strictly necessary there. Where it IS necessary is for loops, and IF statements, etc, where you need more then one step...

IF EXISTS (SELECT * FROM my_table WHERE id = @id)
BEGIN
   INSERT INTO Log SELECT @id, ‘deleted‘
   DELETE my_table WHERE id = @id
END




http://stackoverflow.com/questions/1180279/when-do-i-need-to-use-begin-end-blocks-and-the-go-keyword-in-sql-server

begin--end和go

标签:

原文地址:http://www.cnblogs.com/mingmingrose/p/4185845.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!