Why are stored procedures more efficient than SQL statements?

Source: Internet
Author: User

Stored procedures are precompiled and SQL queries are not

SQL statements need to be processed by the database engine as a low-level instruction before executing

-------------------------------------------------------

if it is performed only once, the stored procedure is not necessarily more efficient than the SQL statement. Because the stored procedure has a pre-compiled procedure. It's just. After you start the server or after the first execution (you can set it). You can load the stored procedure into the cache so that you don't have to compile it later. The efficiency of execution is certainly high. In addition, the execution of stored procedures requires only a few parameters to be passed: It may take a large string to use a statement. Effectively reduces the delivery of data.

-------------------------------------------------------

1 stored procedures allow standard component-type programming
SQL that a stored procedure can be called multiple times in a program after it is created without having to rewrite the stored procedure
statement and the database professional can modify the stored procedure at any time without affecting the application source code because
The application source code contains only the call statement of the stored procedure, which greatly improves the portability of the program .
2 stored Procedures enable faster execution
If an operation contains a large number of Transaction-sql code or is executed more than once, the stored procedure is
is much faster than batch execution because a stored procedure is precompiled when a stored procedure is first run, the query optimizer optimizes it for analysis and gives a transaction-that is eventually batched by the execution plan in the existing system table
SQL statements are compiled and optimized each time they are run, so the speed is relatively slow
3 stored procedures can reduce network traffic
for the same operation on a data database object, such as a query modification, if this operation involves
The TRANSACTION-SQL statement is organized into a stored procedure, and then when the stored procedure is called on the client computer
It is only the calling statement that is transferred in the network, otherwise it will be more than one SQL statement, thus greatly increasing the network traffic drop
Low Network Load
4 stored procedures can be used as a security mechanism to take full advantage of
The system administrator restricts the ability to execute a stored procedure to enable the corresponding data
restricting access to data by non-authorized users to ensure data security
 

Why are stored procedures more efficient than SQL statements?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.