問(wèn)題描述
TechNet 的 BEGIN...END 描述讓我對(duì)以下評(píng)論感到困惑:
The BEGIN...END description of TechNet make me confused with following remark:
盡管所有 Transact-SQL 語(yǔ)句在 BEGIN...END 塊中都有效,但某些 Transact-SQL 語(yǔ)句不應(yīng)組合在同一個(gè)批處理(語(yǔ)句塊)中.
Although all Transact-SQL statements are valid within a BEGIN...END block, certain Transact-SQL statements should not be grouped together within the same batch (statement block).
https://technet.microsoft.com/en-us/library/aa225998(v=sql.80).aspx
誰(shuí)能告訴我為什么不應(yīng)該將它們分組在 BEGIN ... END 塊中?當(dāng)我使用 BEGIN...END 創(chuàng)建區(qū)域時(shí)是否有任何問(wèn)題作為這個(gè)建議:sql server #region?
Could anybody tell me why they shouldn't be grouped within a BEGIN ... END block? Is there any problem when I use BEGIN...END to create region as this suggestion: sql server #region?
推薦答案
如果需要在 T-SQL 腳本中創(chuàng)建多個(gè)批處理,則需要使用 GO
語(yǔ)句明確分隔命令組.因此,即使您沒(méi)有將 BEGIN...END 塊(批處理)顯式添加到代碼中,它也會(huì)隱式創(chuàng)建.因此,明確添加它不應(yīng)該給您帶來(lái)任何額外的麻煩.
If you need to create multiple batches in T-SQL script, you need to separate the group of commands explicitly with the GO
statement. So BEGIN...END block (batch) is created implicitly even if you do not add it explicitly to your code. So adding it explicitly shoud not create any additional troubles for you.
某些命令不能按照鏈接的 MSDN 文章:
創(chuàng)建默認(rèn)值、創(chuàng)建函數(shù)、創(chuàng)建過(guò)程、創(chuàng)建規(guī)則、創(chuàng)建TRIGGER 和 CREATE VIEW 語(yǔ)句不能與其他批處理語(yǔ)句.CREATE 語(yǔ)句必須開(kāi)始批處理.全部該批次中的其他語(yǔ)句將被解釋為一部分第一個(gè) CREATE 語(yǔ)句的定義.
CREATE DEFAULT, CREATE FUNCTION, CREATE PROCEDURE, CREATE RULE, CREATE TRIGGER, and CREATE VIEW statements cannot be combined with other statements in a batch. The CREATE statement must begin the batch. All other statements that follow in that batch will be interpreted as part of the definition of the first CREATE statement.
一個(gè)表不能被改變,然后在表中引用的新列同一批.
A table cannot be altered and then the new columns referenced in the same batch.
如果 EXECUTE 語(yǔ)句是批處理中的第一條語(yǔ)句,則 EXECUTE關(guān)鍵字不是必需的.EXECUTE 關(guān)鍵字是必需的,如果EXECUTE 語(yǔ)句不是批處理中的第一條語(yǔ)句.
If an EXECUTE statement is the first statement in a batch, the EXECUTE keyword is not required. The EXECUTE keyword is required if the EXECUTE statement is not the first statement in the batch.
這篇關(guān)于為什么不應(yīng)該將 Transact-SQL 語(yǔ)句組合在同一個(gè)批處理中?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!