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!) )