SQL Server-Stored Procedure

Source: Internet
Author: User

Two days ago, we briefly learned about a special stored procedure-trigger. Today we want to write some simple theoretical and practical knowledge about the stored procedure.

First, we need to understand what is a stored procedure and its format.

Definition:Store common or complex tasks in advance with SQL statements and a specified name, to enable the database to provide services with the same functions as the predefined stored procedure, you only need to call execute to automatically complete the command.

Format:

-- ===================================================== ====== -- Author: <author> -- Create date: <creation date> -- Description: <description> -- ============================================ ========== create procedure <Stored PROCEDURE Name> -- add a stored PROCEDURE parameter <@ parameter, data Type •> ASBEGIN -- program line, specific operation process ENDGO

PS: the stored procedure name can contain a maximum of 128 characters, and a maximum of 1024 parameters can be added (which can be left blank). It can be executed by the exec stored procedure name.

Here is an example.Practical ApplicationStored Procedure

USE [DB_rechargeSystem] GO/****** Object: StoredProcedure [dbo]. [proc_T_UserInfoDelete] Script Date: 11:00:32 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO -- ================ =================================-- Author: old ox -- Create date: -- Description: delete user information -- =============================================== ========= create procedure [dbo]. [proc_T_UserInfoDelete] @ userID int ASBEGIN -- first delete user information delete T_UserInfo where userID = @ userID END

PS: delete user information through userID.

1. Check whether the execution is successful. Let's take a look at the information in the T_UserInfo table first.


2. Execute the Stored Procedure

exec proc_T_UserInfoDelete 3

3. view results



PS: we can find that the stored procedure is successfully executed.

The above is a brief introduction to stored procedures. Why should we use stored procedures? When should we use stored procedures? In fact, we can use the memory when we encounter another problem.

A. in data, an operation appears multiple times (reuse)

B. High system performance requirements (improved performance)

C. When processing highly concurrent data operations (reducing network traffic)

D. The requirement for system security is (to improve security)

 

(If there are any omissions in cainiao's work, please do not hesitate to inform me !)





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.