SQL Summary 4. SQL Summary

Source: Internet
Author: User

SQL Summary 4. SQL Summary

Speaking of SQL, the stored procedure is undoubtedly very important. This article will discuss the stored procedure with you.

1: storage process

A: stored without Parameters

USE testGOCREATE procedure wly -- stored PROCEDURE without the ASSELECT * FROM roleGO Parameter

B: stored with Parameters

USE testGOCREATE PROCEDURE WLY1 @A INTAS DECLARE @B INTSET @B=1SET @A=@BPRINT @AGO

C: storage process with output parameters

USE testGOCREATE PROCEDURE WLY2 @ a int output -- OUTPUT parameter as declare @ B intset @ B = 1 select @ A = @ BPRINT @ AGO

D: some parameters of the stored procedure

SP_HELP WLY1 -- return the name, time, and parameter of the stored procedure SP_HELPTEXT WLY1 -- return the creation statement SP_RENAME WLY and WLY2 -- rename the stored procedure GO

E: Execute the Stored Procedure

Execute dbo. WLYEXECUTE WLY1 -- stored procedure with parameters DECLARE @ c int -- output with parameters EXECUTE WLY2 @ C OUTPUTGO

2: cursor

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 @COUNT=@COUNT+1    FETCH NEXT FROM C_ROLE INTO @VRID,@VRNAMEENDCLOSE C_ROLEDEALLOCATE C_ROLEGO 

I feel that the use of cursors should be avoided as much as possible, because the data is retrieved and stored again, and it is not good if the data volume is large.


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.