什么时候应该在 SQL Server 中使用分号? [英] When should I use semicolons in SQL Server?

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

问题描述

在检查 Web 上的一些代码和 SQL Server Management Studio 生成的脚本时,我注意到一些语句以分号结尾.

While checking some code on the web and scripts generated by SQL Server Management Studio I have noticed that some statements are ended with a semicolon.

那么我应该什么时候使用它?

So when should I use it?

推荐答案

来自 SQLServerCentral.Com 文章:

From a SQLServerCentral.Com article by Ken Powers:

分号

分号字符是语句终止符.它是 ANSI SQL-92 标准的一部分,但从未在 Transact-SQL 中使用过.事实上,可以多年编写 T-SQL 代码而不会遇到分号.

The semicolon character is a statement terminator. It is a part of the ANSI SQL-92 standard, but was never used within Transact-SQL. Indeed, it was possible to code T-SQL for years without ever encountering a semicolon.

使用

有两种情况必须使用分号.第一种情况是您使用公共表表达式 (CTE),并且 CTE 不是批处理中的第一个语句.第二个是您发出 Service Broker 语句并且 Service Broker 语句不是批处理中的第一个语句.

There are two situations in which you must use the semicolon. The first situation is where you use a Common Table Expression (CTE), and the CTE is not the first statement in the batch. The second is where you issue a Service Broker statement and the Service Broker statement is not the first statement in the batch.

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

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