在 SQL Server 中,什么时候应该使用 GO,什么时候应该使用分号 ;? [英] In SQL Server, when should you use GO and when should you use semi-colon ;?

查看:64
本文介绍了在 SQL Server 中,什么时候应该使用 GO,什么时候应该使用分号 ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直对什么时候应该在命令后使用 GO 关键字以及命令末尾是否需要分号感到困惑.有什么区别?为什么/何时应该使用它们?

I’ve always been confused with when I should use the GO keyword after commands and whether a semi-colon is required at the end of commands. What is the differences and why/when I should use them?

当我在 SQL Server Management Studio 中运行 Generate-script 时,它似乎到处都在使用 GO,但没有使用分号.

When I run the Generate-script in SQL Server Management Studio, it seems to use GO all over the place, but not the semi-colon.

推荐答案

GO 只与 SSMS 有关 - 它不是实际的 Transact SQL,它只是告诉 SSMS 在每个 GO 分批按顺序进行.

GO only relates to SSMS - it isn't actual Transact SQL, it just tells SSMS to send the SQL statements between each GO in individual batches sequentially.

; 是一个 SQL 语句分隔符,但在大多数情况下,引擎可以解释您的语句被分解的位置.

The ; is a SQL statement delimiter, but for the most part the engine can interpret where your statements are broken up.

主要的例外,以及 ; 最常使用的地方是在公共表表达式语句之前.

The main exception, and place where the ; is used most often is before a Common Table Expression Statement.

这篇关于在 SQL Server 中,什么时候应该使用 GO,什么时候应该使用分号 ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆