The difference between Executeupdate,executequery,executebatch

Source: Internet
Author: User

ExecuteQuery:

Used to implement a single result set, for example:

Select

The general use of ExecuteQuery is a tool to implement a single result set

Executeupdate
Used to execute INSERT, UPDATE, or DELETE statements, as well as SQL DDL (data definition language) statements, such as CREATE table and DROP table. The effect of an INSERT, UPDATE, or DELETE statement is to modify one or more columns in 0 or more rows in a table.

The return value of Executeupdate is an integer that indicates the number of rows affected (that is, the update count). For statements that do not manipulate rows such as CREATE table or DROP table, the return value of executeupdate is always zero.

While Addbatch () and executeupdate () are used to perform data insertions, the difference is a batch, a single insert. These two do not use together, so Addbatch () and not write the same. Addbatch () is used to cache data, cache multiple SQL statements, and then pass the ExecuteBatch () method to the database at once, greatly improving the efficiency of execution. Executeupdate () Focus on timeliness, each write a SQL statement sent to the database to save, no cache, so the frequent operation of the database is very inefficient.
It is also important to note that when you use Addbatch () to cache data, you set conditions in the loop, execute ExecuteBatch () when the loop reaches a specified number of times, send all the SQL in the cache to the database, and then perform a clear cache of Clearbatch (). Otherwise, the data is too large to appear outofmemory (low memory).

The difference between Executeupdate,executequery,executebatch

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.