When it comes to SQL, there is no doubt that stored procedures are important, and this article discusses the storage process.
1: Storage Process
A: Stored procedure without parameters
Use testgocreate PROCEDURE wly -stored procedure without parameters Asselect * from Rolego
B: Stored procedure with parameters
Use testgocreate PROCEDURE WLY1 @A intas DECLARE @B intset @b=1set @[email protected]print @AGO
C: Stored procedure with output parameters
Use testgocreate PROCEDURE WLY2 @A INT output -parameter value parameters as DECLARE @B intset @b=1select @[email protected]print @AGO
D: Some parameters of the stored procedure
sp_help WLY1 --Returns the name of the stored procedure, time, parameters, etc. sp_helptext WLY1--Returns the creation statement of the stored procedure sp_rename wly,wly2 --Renaming the stored procedure go
E: Execute the storage process
Execute dbo. Wlyexecute WLY1 1--stored procedure with parameters declare @c INT --Output with parameters execute WLY2 @c outputgo
2: Cursors
DECLARE c_role CURSOR scrollfor SELECT rid,rname from rolefor READ onlydeclare @COUNT int, @VRID int, @VRNAME VARCHAR (1) OPEN C_rolefetch NEXT from C_roleinto @VRID, @VRNAMESET @COUNT =0while @ @FETCH_STATUS =0begin print @VRID print @ Vrname PRINT @COUNT SET @[email protected]+1
I feel the use of cursors as much as possible, because it is to take out the data and save it, if the amount of data is very large, it is not good.
SQL Personal Summary 4