分号是在数据库系统中分隔每条 SQL 语句的标准方法,这样就可以在对服务器的相同请求中执行一条以上的语句。
如果您使用的是 MS Access 和 SQL Server 2000,则不必在每条 SQL 语句之后使用分号,不过某些数据库软件要求必须使用分号。
用习惯了oracle后,习惯在每个语句结束后以(;)结尾。
但是在sql中有哪些情况是必须使用分号的呢?
从一些英文文献中发现:
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.
我们来解释一下上面的两种情况:
第一种:
declare @t table(id int)
insert into @t
select 1 union
select 3 union
select 4
;with cr as
(
select * from @t
)
select * from cr
/*
id
-----------
1
3
4
*/
这里with前面的分号是必须要有的。
第二种:
--创建主密钥:
create master key encryption by password = 'Pass.word';
--发送和接收
waitfor (
receive top(1)
@message_type = message_type_name,
@message_body = message_body,
@dialog = conversation_handle
from dbo.InventoryQueue
), timeout 2000;
为了确保分析器能知道SEND和RECEIVE正是在开始一个新命令,SEND或RECEIVE之前的命令必须以
分号(;)结束.
————————————————
版权声明:本文为CSDN博主「shi8rrj2575」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/shi8rrj2575/article/details/41084219