Why use stored procedures

A stored procedure is simply a combination of a bunch of SQL. Add some logic control in the middle.

But the stored procedure is more practical when dealing with more complex business.
For example, a complex data manipulation. If you handle it at the front desk. Multiple database connections may be involved. But if you use stored procedures. Just once. It has an advantage in terms of response time.
That is to say, stored procedures can bring us the benefits of improving operational efficiency.
In addition, the program is prone to bugs and instability, and stored procedures, as long as the database does not have problems , basically there will be no problems. That is to say, in terms of security, the system using the stored procedure is more stable.

Items with small amounts of data, or projects that have nothing to do with money, can work without a stored procedure. mysql's stored procedures have yet to be tested in practice. If it is a formal project, it is recommended that you use sql server or oracle stored procedures. When dealing with data, the process will be much faster than the program. The interviewer asked if there is any use for storage, in fact, he wanted to know whether the programmer who came to interview has done a project with a large amount of data. If it is from training, or from small projects and small companies, there must be less contact with storage.

Therefore, if you want to enter a large company, it is impossible without rich experience in stored procedures.

So when will the storage be available? Is it unnecessary for small projects where the amount of data is not very large and the business processing is not very complicated?
wrong. Stored procedures are not only suitable for large-scale projects, for small and medium-sized projects, the use of stored procedures is also very necessary. Its power and advantages are mainly reflected in:
  1. The stored procedure is only compiled when it is created, and it does not need to be recompiled every time the stored procedure is executed in the future , and the general SQL statement is compiled once every time it is executed, so the use of stored procedures can improve the database. execution speed.
  2. When performing complex operations on the database (such as Update, Insert, Query, and Delete on multiple tables), this complex operation can be encapsulated in a stored procedure and used in conjunction with the transaction processing provided by the database. These operations, if done by a program, will become a series of SQL statements, which may require multiple connections to the database. Instead of storage, you only need to connect to the database once.
  3. Stored procedures can be reused , which can reduce the workload of database developers.
  4. High security , it can be set that only a certain user has the right to use the specified stored procedure.

 

 

Source: blog.csdn.net/defonds/article/details/4349922

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326710057&siteId=291194637