Data Center reconstruction-stored procedure and stored procedure Reconstruction
I have only seen the word stored procedure. I know such a thing, but I didn't really reveal it to really understand it. But I encountered a problem when I knocked on the data center, to modify the data of multiple tables in the database, it will be complicated to use SQL statements. What can improve our efficiency? The stored procedure can be done, which forces me to touch the stored procedure again.
Definition: a set of SQL statements that complete specific functions in a large database. It is equivalent to writing an SQL statement that needs to be written multiple times at Layer D in the database.
When the stored procedure will be used, we can see from the definition that the stored procedure is a collection of SQL statements. When the SQL statements we use are complex, using the stored procedure can simplify our work. We need to make a good estimate of the complexity and use stored procedures in a timely manner. Not all stored procedures are very good.
The following uses the registration card as an example to describe how to use the stored procedure:
USE/***** Object: StoredProcedure [dbo]. [PROC_Register] Script Date: 03/15/2015 15:32:58 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO -- ================ =================================-- Author: <sisi> -- Create date: <12:02:28> -- Description: <registration> -- ========================================== ========= alter procedure [dbo]. [PROC_Register] -- Add the parameters for the stored procedure here @ cardID char (10), @ studentID char (10), @ account char (10), @ cardType char (10 ), @ usingState char (10), @ remark varchar (50), @ registrationDate char (10), @ registrationTime char (10), @ UserID char (10 ), @ studentName char (10), @ sex char (10), @ department char (10), @ grade char (10), @ studentclass char (10 ), @ RechargeDate char (10), @ RechargeTime char (10), @ RechargeMoney decimal () ASBEGIN -- add a card table insert into T_CardInfo (cardID, studentID, account, cardType, usingState, remark, registrationDate, registrationTime, UserID) values (@ cardID, @ studentID, @ account, @ cardType, @ usingState, @ remark, @ registrationDate, @ registrationTime, @ UserID) -- add the student table insert into T_StudentInfo (studentID, studentName, sex, department, grade, studentclass) values (@ studentID, @ studentName, @ sex, @ department, @ grade, @ studentclass) -- add the insert into partition (cardID, RechargeDate, RechargeTime, RechargeMoney, UserID) values (@ cardID, @ RechargeDate, @ RechargeTime, @ RechargeMoney, @ UserID) END
When I see the stored procedure, I think of the functions that we often use. What is the difference between them?
Through the comparison above, we may have a deeper understanding of stored procedures. We have learned and often used functions by associating stored procedures with functions, in this way, we will not fear it any more. We have not learned it, but may not have discovered that we have already seen it. We need to discover the prototype of unfamiliar things from the existing knowledge.