加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

Sqlserver 中必须使用分号的两种情况--【叶子】

发布时间:2020-12-12 15:34:08 所属栏目:MsSql教程 来源:网络整理
导读:用习惯了 oracle 后,习惯在每个语句结束后以 ( ; ) 结尾。 但是在 sql 中有哪些情况是必须使用分号的呢 ? ? 从一些英文文献中发现: ? There are two situations in which you must use the semicolon. The first situation is where you use a Common Ta

用习惯了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

3 union

4

?

;with cr as

(

??? select * from @t

)

* 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,"serif"; mso-no-proof: yes;'>???? @dialog?????? = conversation_handle

??? from dbo.InventoryQueue

? ), timeout 2000;

?

为了确保分析器能知道SENDRECEIVE正是在开始一个新命令,SENDRECEIVE之前的命令必须以

分号(;)结束.

?

@【叶子】http://blog.csdn.net/maco_wang 原创作品,转贴请注明作者和出处,留此信息。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读