sqlsever--Transactions and Indexes

Source: Internet
Author: User

Question thrown:

When executing multiple SQL statements at the same time, if one of the statements has an error and the other statements are executed correctly, the database data will not be on the line. With the business!

Transactions (Transaction)

Concept: A transaction performs a series of operations as a logical unit of work, which is performed as a whole, or all is not executed, ensuring data consistency!

Characteristics:

Classification:

Explicit transactions: Begins with a BEGIN transaction explicit transaction.

Implicit transactions:

Commit transactions automatically:

Each individual SQL statement is automatically defaulted to a transaction.

How does a transaction work?

When a transaction starts, all operations are first written to the log, and when the entire process is error-free, all operations in the transaction are committed once, and if there is an error in the execution, the previous action is revoked. Even when a database exception is caused by an external cause during the execution of a transaction, the next time you start the database, you will be able to complete the unfinished operation based on the log contents.

Creation and use of transactions

Basic steps:

Start transaction: Begin TRANSACTION

Commit TRANSACTION: Commit TRANSACTION

ROLLBACK TRANSACTION: ROLLBACK TRANSACTION

Use @ @error to determine whether you want to roll back or commit.

code example:

Ado. NET for transaction writing:

Index

The use of the index is used to improve the query speed, and so on after the actual need to contact to add!

sqlsever--Transactions and Indexes

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.