What is a database stored procedure?

What is a stored procedure?

先看一下百度词条给的答案

Stored procedure (Stored Procedure) is a large database system, in order to complete a specific set of functions set of SQL statements, it is stored in the database, a permanent after compilation, the user specifies the name of the stored procedure and the given parameters (if the stored procedure with parameters) to execute it. A stored procedure is an important object in the database.

通俗讲

A stored procedure is a precompiled SQL statements, such as sql some scenes is more complex and requires frequent use or multiple use. Advantage of stored procedures is to say simply create a compiled once and can be directly invoked several times in the program. If a sql often need to operate, and the logic is not easy to change, use the stored procedure is faster than simple SQL statement is executed, because sql and all you need to compile each query. And network overhead is large, stored procedures need only pass a name, the database calls on the line, and this program portable high

When using stored procedures, there is no need to use a small project?

Or use small projects to look at the importance of this project, as well as configure all aspects of the team
because of poor maintainability stored procedures, readability is also relatively poor
if efficiency is not particularly demanding, you can choose not to

Advantages of the stored procedure is more obvious

  • efficient

    Stored procedure only when creating compiled, each subsequent implementation of the storage process is not need to recompile the general SQL statement is executed once each time the compiler, so the use of stored procedures can improve database speed of execution

  • Reducing the cumbersome steps

    When complex database operations (such as multiple tables Update, Insert, Query, when Delete), complicated operation may be encapsulated with this procedure it stored transaction database used in conjunction with supplied. These operations, if the procedure is done, it becomes a section of the SQL statement, you may want to connect to the database several times. And into storage, only need to connect to a database on it
    and stored procedures can be reused, you can reduce the workload of database developers

  • Safety

    Safe, can be set only a user only has the right to use the specified stored procedure

Disadvantages of stored procedures

  • Maintainability and readability check
    Logic design and will be even more complicated to write than the sql statement, there is no flexibility sql statement
    stored procedure requires specialized database developer for maintenance, but the reality is often a part-time program developers

To sum up either to use or to measure the actual situation

Published 171 original articles · won praise 386 · views 160 000 +

Guess you like

Origin blog.csdn.net/weixin_42837024/article/details/102796931