Go in T-SQL

Source: Internet
Author: User

Source: http://www.cnblogs.com/JCSU/articles/1099177.html8Dju O & jv0

+ H | fqu5z (ha6 _ + w0go is used in Sybase and SQL Server to indicate the end of the transaction, submit and confirm the result, which is equivalent to the Oracle commit51testing software testing network d ed C % t'k
IW {3 W/Wm 'td0sql server utility interprets go as a signal that the current Transact-SQL batch processing statement should be sent to SQL Server. The current batch processing statement is all the statements entered after the previous go command. If it is the first go command, it is all the statements from the beginning of a special session or script to the beginning of this go command. HD; pwek0' OC) F. cz: ZB * o0go command and transact-SQL statement cannot be on the same line. However, the go command line can contain comments. 51testing software testing network BT) yvt & Tuf users must follow the batch processing rules. For example, after the first statement in the batch processing, any stored procedure must contain the execute keyword. The scope of local (User-Defined) variables is limited to one batch and cannot be referenced after the go command. 51testing software testing network; wx {JX-T: Qu

Use pubs n xa] % y0go. p/^) t {^ f1m8ywgv0declare @ mymsgvarchar (50) 3be & kgy8y1pb @ 0select @ mymsg = 'hello, world. '51testing Software Testing Network s "NN-OQ7ws3m8v go -- @ mymsg is not valid after this go ends the batch. 51testing software testing network ry8dku7s' {z $ p3j 51testing software testing network EC (B HC 'ga PT -- yields an error because @ mymsg not declared in this batch. 51testing software testing network "n {up. UKB print @ mymsg 51testing G-Sb f'f8f-V go

W (H/N, b5n8w0

Select @ version; t [3 V: vh0 -- yields an error: Must be exec sp_who if not first statement in) noq | ^ e! C0 -- batch. la8o % L! P0sp_who W $ p] % x1e0go 51testing Software Testing Network/Oz * QQ ~ E * \ & QG

51testing software testing network 0j: r_xh4? G

SQL Server Applications can send multiple Transact-SQL statements as one batch to SQL Server for execution. The statements in this batch are compiled into an execution plan. The programmer executes a specific statement in the SQL Server utility or generates a Transact-SQL statement script to run in the SQL Server utility, and uses go to identify the end of batch processing. 'Y, tj5y |. Y \ 0 if an application based on DB-library, ODBC, or ole db APIs tries to execute the go command, it will receive a syntax error. SQL Server utility never sends go commands to the server. 51testing software testing network bcl3r {| ca permission 51testing software testing network WVX 'l7w; u2o} 4x ^ go is a utility command without permission. It can be executed by any user. }-{G4km0f0 example 51testing iwbmjqy the following example creates two batches. The first batch contains only one use pubs statement for settingDatabaseContext. The remaining statement uses a local variable, so all local variable declarations must be in a batch. This can be done by using the go command only after the last statement that references this variable.

Y3nze * wx3 [6 _ 't0

Use pubs 4b7 \ 3l % sgd8f0go 51testing software testing network r'qa (kx declare @ nmbrauthorsint 51testing software testing network U "D: cxy6q_a select @ nmbrauthors = count (*) 'N' \ cobjl/j0from authors 51testing software testing network W! '* E! V % KH print 'the number of authors as of '+ 51testing wie; ei3kh9j? Cast (getdate () aschar (20) + 'is + & v7q ^ m. d' gv0 cast (@ nmbrauthorsaschar (10), u-s: dknaj0z; '0go
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.