In personal learning to write SQL Server stored procedures, for stored procedures in the keyword as, go keyword does not understand, the online view a lot of information. Here, I have a personal summary.
========================as, go say a =======================
Go is used to submit its previous T-SQL statements as a batch to the SQL Server instance in SSMS and SQLCMD. Go is not a T-SQL statement, just a way of submitting batches specified by these specific clients. Batch processing (Batch) is a collection of one or more T-SQL statements that the SQL SERVER client sends to the service as a unit-the client submits the collection to the instance one at a time, and the service compiles it into an execution plan. When ANSI_NULLS is enabled, all comparison operations with null values result in UNKNOWN, otherwise null and null values are compared to TRUE.
Enabling QUOTED_IDENTIFIER indicates that double quotes ("") are used as delimiters (you can use "or [] as a delimiter when identifiers do not conform to SQL SERVER's naming conventions.)
As is actually a keyword, it can be understood in a stored procedure to define a T-SQL statement that is down (to go) as a stored procedure.
========================as, go say two =======================
Go is NOT a Transact-SQL statement; It is a command that can be identified by the SQLCMD and osql utilities and the SQL Server Management Studio Code Editor.
The SQL Server utility interprets go as a signal that the current batch of Transact-SQL statements should be sent to an instance of the server. The current batch statement consists of all statements entered after the previous Go command, or, if it is the first to go command, consisting of all statements entered after the Ad hoc session or script starts.
The GO command and Transact-SQL statements cannot be in the same row. However, you can include comments on the GO command line.
As part of the syntax of the stored procedure, which is the definition of stored procedure parameters and attributes, as followed by the definition of the contents of the stored procedure
Use [database_name] Go Set ANSI_NULLS on Go Set QUOTED_IDENTIFIER on Go--=============================================- -Author: <Author,,Name>-Create Date: <create date,,>--Description: <Description,,>--=========== ================================== CREATE PROCEDURE [dbo].
[Proc_user_test] (--Set the parameter @citizenId char (10),--Owner ID @goodsId char (12),--Commodity ID @goodsNum int,--Number of items @ElectronDeviceNo varchar (20),--Electronic scale number @exchangeInt int,--Exchange integral @recycleExchangeInt int,--Exchange recovery points @exchangetime datetime,--Exchange time @int I NT output--parameters for output--as BEGIN try--Set local variable declare @throwExchangeInt int;
--Redemption points, the default value is 0, how to set. Declare @userId char (10); --Operator ID declare @primaryKey varchar (20);
--Unique identity begin TRAN-INSERT INTO Gar_electrondevicegoodsorder (?,?,?,?) --Insert electronic scale Commodity Exchange record information insert into Gar_electrondevicegoodsorder (Citizenid, Goodsid, Goodsnum, Electrondeviceno, E Xchangeint, Throwexchangeint, Recycleexchangeint, pIckexchangeint, UserId, Exchangetime) VALUES (@citizenId, @goodsId, Goodsnum, @ElectronDeviceNo, @exchangeInt,
0, @recycleExchangeInt, 0, @userId, @exchangetime);
--here, whether to obtain a primary key unique identity. Set @primaryKey = @ @IDENTITY--Update owner integral change update Gar_citizen set intcurrency = (intcurrency-@exchangeInt), I Ntspend = (intspend + @exchangeInt), Recycleexchangeint = (recycleexchangeint + @recycleExchangeInt) where
Citizenid = @citizenId;
End Try begin catch Set @int = Error_severity ();
if (@ @trancount > 0) begin rollback Tran End catch if (@ @trancount > 0) Begin commit Tran Set @int = 0; End Select @int as code--what does it mean.
Do not understand--the following 4 lines of code is the establishment of stored procedures, the system automatically added statements--set NOCOUNT on; --Insert statements for procedure--SELECT < @Param1, sysname, @p1, < @Param2, sysname, @p2 >--end go