Database-stored procedure (concept, advantages and disadvantages, classification)

(1) Concept:

    ① Stored Procedure (Stored Procedure) is a set of SQL statements to complete a specific function. Stored in the database after compilation.

    ② The stored procedure is an important object in the database. The user executes it by specifying the name of the stored procedure and giving parameters (if the stored procedure has parameters).

    ③ Stored procedure is a process written by flow control and SQL statements, which is stored in the database server after compilation and optimization.

    ④ The stored procedure can be executed by the application through a call, and allows the user to declare variables.

    ⑤ At the same time, the stored procedure can receive and output parameters, return the status value of the execution of the stored procedure, or nested calls.

(2) Advantages:

    ① Enhanced the function and flexibility of SQL statements

    ② No need to repeatedly establish a series of processing steps to ensure the integrity of the data

    ③ Reduce the network traffic, the client calls the stored procedure only need to pass the stored procedure name and related parameters, compared with the transmission of SQL statements, the amount of natural data is much less

    ④ The security of use is enhanced, and users without authority can indirectly access the database under control through the stored procedure, thereby ensuring the security of the data.

    ⑤ Centralized control can be achieved. When the rules change, you only need to modify the stored procedure.

(3) Disadvantages:

    ① Commissioning is not very convenient

    ② May not have the right to create stored procedures

    ③ Recompile problem

    ④ transplantation problem

(4) Classification:

    ① System storage process: It starts with sp_ and is used to make various settings of the system. Obtain information. Related management work. 

    ② Local stored procedure: The stored procedure created by the user is a stored procedure created by the user and completed a certain function. In fact, the stored procedure generally refers to the local stored procedure.

    ③ Temporary stored procedures: divided into two types of stored procedures: 

One is a local temporary stored procedure, with the pound sign (#) as the first character of its name, the stored procedure will become a local temporary stored procedure stored in the tempdb database, and only the user who created it can execute it;

The second is a global temporary stored procedure, starting with two pound signs (##), the stored procedure will become a global temporary stored procedure stored in the tempdb database. Once the global temporary stored procedure is created, any connection to the server in the future Users can execute it, and no specific permissions are required.

    ④ Remote stored procedures: In SQL Server 2005, remote stored procedures (Remote Stored Procedures) are stored procedures located on a remote server, you can usually use distributed queries and EXECUTE commands to execute a remote stored procedure.

    ⑤ Extended stored procedures: Extended stored procedures (Extended Stored Procedures) are stored procedures that users can write in external programming languages, and the names of extended stored procedures usually start with xp_

Guess you like

Origin www.cnblogs.com/nyhhd/p/12686532.html