SQL Personal Summary 4

Source: Internet
Author: User

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

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.