SQL Server---stored procedures

Source: Internet
Author: User

Two days ago we simply learned about a special kind of stored procedure-trigger-related knowledge, today is to write about the stored procedures of some simple theory and practical application of knowledge.

First, we need to understand what a stored procedure is, and how it is formatted.

definition: the use of common or very complex work, pre-written SQL statements and stored with a specified name, then to call the database to provide the functions of the defined stored procedures with the same functionality, just call execute, you can automatically complete the command.

Format:

--=============================================--author:< author >--Create date      : < creation date >--Description: < description >--=============================================create PROCEDURE < stored procedure name >--Add parameters for stored procedures <@ parameter, data type??? >  asbegin--program Line, the specific operation process Endgo

PS: Stored procedure names can have up to 128 characters, up to 1024 parameters can be added (not available), and executed with the Exec stored procedure name.

Here's an example of how we can actually use the stored procedure

Use [db_rechargesystem]go/****** Object:  StoredProcedure [dbo].[ Proc_t_userinfodelete] Script date:2014-06-05 11:00:32 ******/set ansi_nulls ongoset quoted_identifier ONGO--========= ====================================--Author: Lao Niu--Create date:2014-6-5 11:00--Description: Delete News--================= ============================create PROCEDURE [dbo]. [Proc_t_userinfodelete] @userID int asbegin--First delete user information delete t_userinfo where UserID [email protected] END

PS: Delete user information through UserID.

1. To know if 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: Compare we can find that the stored procedure executes successfully

The above is a simple introduction to the stored procedure, then why do we need to use the stored procedure? When do we use stored procedures? We can actually use the memory when we have another problem.

A. In the data, a single operation occurs multiple times (repeated use)

B. When the system performance requirements are high (improve performance)

C. When handling high data concurrency (reduce network traffic)

D. Requirements for system security (increased security)

(Rookie works if there are flaws, but also please enlighten!) )





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.