Home Database Mysql Tutorial SQL Server 中的事务(含义,属性,管理)

SQL Server 中的事务(含义,属性,管理)

Jun 07, 2016 pm 04:18 PM
server affairs meaning Attributes manage

含义: 事务要有非常明确的开始和结束点,SQL Server 中的每一条数据操作语句,例如SELECT、INSERT、UPDATE和DELETE都是隐式事务的一部分。即使只有一条语句,系统也会把这条语句当做一个事务,要么执行所有的语句,要么什么都不执行。 事务开始之后,事务所

  含义:

  事务要有非常明确的开始和结束点,SQL Server 中的每一条数据操作语句,例如SELECT、INSERT、UPDATE和DELETE都是隐式事务的一部分。即使只有一条语句,系统也会把这条语句当做一个事务,要么执行所有的语句,要么什么都不执行。

  事务开始之后,事务所有的操作都会写到事务日志中,写到日志中的事务,一般有两种:一是针对数据的操作,例如插入、修改和删除,这些操作的对象是大量的数据;另一种是针对任务的操作,例如创建索引。当取消这些事务操作时,系统自动执行这些操作的反操作,,保证系统的一致性。系统自动生成一个检查点机制,这个检查点周期的检查事务日志。如果在事务日志中事务全部完成,那么检查点事务日志中的事务提交到数据库中,并且在事务日志中做一个检查点提交标识;如果在事务日志中,事务没有完成,那么检查点不会将事务日志中的事务提交到数据库中,并且在事务日志中做一个检查点未提交的标识。事务的恢复及检查点保证了系统的完整和可恢复。

  事务的属性:

  事务是作为单个逻辑工作单元执行的一系列操作。一个逻辑工作单元必须有4个属性,称为原子性(Atomic)、 一致性(Consistent)、隔离性(Isolated)、持久性(Durable),简称ACID属性,只有这样才能构成一个事务。

  原子性:

  整个事务中的所有操作,要么全部完成,要么全部不完成,不可能停滞在中间某个环节。事务在执行过程中发生错误,会被回滚(Rollback)到事务开始前的状态,就像这个事务从来没有执行过一样。

  一致性:

  在事务开始之前和事务结束以后,数据库的完整性约束没有被破坏。

  隔离性:

  两个事务的执行是互不干扰的,一个事务不可能看到其他事务运行时,中间某一时刻的数据。

  持久性:

  在事务完成以后,该事务所对数据库所作的更改便持久的保存在数据库之中,并不会被回滚。

  由于一项操作通常会包含许多子操作,而这些子操作可能会因为硬件的损坏或其他因素产生问题,要正确实现ACID并不容易。ACID建议数据库将所有需要更新 以及修改的资料一次操作完毕,但实际上并不可行。

  事务管理的常用语句:

  BEGIN TRANSACTION——建立一个事务

  COMMITTRANSACTION——提交事务

  ROLLBACK TRANSACTION——事务失败时执行回滚操作

  SAVE TRANSACTION——保存事务

  BEGIN TRANSACTION 和COMMIT TRANSACTION同时使用,用来表示事务的开始和结束。

  事务的隔离级别:

  事务具有隔离性,不同事务中所使用的时间必须要和其他事务进行隔离,在同一时间可以有很多个事务正在处理数据,但是每个数据在同一时刻只能有一个事务进行操作。如果将数据锁定,使用数据的事务就必须要排队等待,这样可以防止多个事务互相影响。但是如果有几个事务因为锁定了自己的数据,同时又在等待其他事务释放数据,则造成死锁。

  为了提高数据的并发使用效率,可以为事务在读取数据时设置隔离状态,SQL Server 2012 中的事务隔离状态由低到高分为5个级别。

  未授权读取

  也称为读未提交(Read Uncommitted):允许脏读取,但不允许更新丢失。如果一个事务已经开始写数据,则另外一个数据则不允许同时进行写操作,但允许其他事务读此行数据。该隔离级别可以通过“排他写锁”实现。

  授权读取

  ,也称为读提交(Read Committed):允许不可重复读取,但不允许脏读取。这可以通过“瞬间共享读锁”和“排他写锁”实现。读取数据的事务允许其他事务继续访问该行数据,但是未提交的写事务将会禁止其他事务访问该行。

  可重复读取

  可重复读取(Repeatable Read):禁止不可重复读取和脏读取,但是有时可能出现幻影数据。这可以通过“共享读锁”和“排他写锁”实现。读取数据的事务将会禁止写事务(但允许读事务),写事务则禁止任何其他事务。

  序列化

  序列化(Serializable):提供严格的事务隔离。它要求事务序列化执行,事务只能一个接着一个地执行,但不能并发执行。如果仅仅通过“行级锁”是无法实现事务序列化的,必须通过其他机制保证新插入的数据不会被刚执行查询操作的事务访问到。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is WICC Coin? What is WICC Coin? Feb 21, 2024 pm 06:00 PM

What is WICC Coin? WICC Coin is the abbreviation of WaykiChainCoin, which is a digital currency based on blockchain technology. As an efficient, scalable and secure public chain, WaykiChain is committed to providing enterprises and developers with complete blockchain infrastructure and innovative tools. As the core token of the WaykiChain ecosystem, WICC Coin plays an important role on the platform. Features of WICC currency 1. Safe and reliable: WaykiChain adopts the DPoS consensus algorithm and has a reliable distributed locking mechanism and consensus mechanism to ensure a high degree of network security. 2. Efficient and scalable: WaykiChain has millisecond-level transaction confirmation speeds, can handle thousands of transactions per second, and

Understand the meaning of eol in PHP Understand the meaning of eol in PHP Mar 20, 2024 am 11:09 AM

In-depth understanding of the meaning and code examples of eol in PHP In PHP programming, eol is a common term that represents "EndOfLine", which is the end of the line. In different operating systems, the end of a line may be expressed differently, which leads to the concept of eol. In Windows systems, the end of a line is composed of carriage return () and line feed (), that is, ""; while in Unix/Linux systems, the end of a line is only represented by line feed (), that is, "". Such differences may result in different operating systems

How to turn off the content display function of Kuaishou private messages? What does it mean to turn off the display content of Kuaishou private messages? How to turn off the content display function of Kuaishou private messages? What does it mean to turn off the display content of Kuaishou private messages? Mar 21, 2024 pm 05:41 PM

As the leading short video platform in China, Kuaishou has a large number of users, and the private messaging function is an important channel for interaction between users. However, some users may find the ability to display content in private messages bothering them and would like to be able to selectively turn this feature off. 1. How to turn off the content display function of Kuaishou private messages? 1. Open the Kuaishou app and log in to your personal account. 2. Enter the Kuaishou main interface and click the "My" button in the lower right corner to enter the personal center. 3. On the personal center page, click the avatar to enter personal settings. 4. On the personal settings page, find the "Privacy Settings" option and click to enter. 5. On the privacy settings page, find the "Display content in private messages" option and click to enter. 6. On the private message display content setting page, turn off the "private message display content" function

How to install, uninstall, and reset Windows server backup How to install, uninstall, and reset Windows server backup Mar 06, 2024 am 10:37 AM

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

MySQL transaction processing: the difference between automatic submission and manual submission MySQL transaction processing: the difference between automatic submission and manual submission Mar 16, 2024 am 11:33 AM

MySQL transaction processing: the difference between automatic submission and manual submission. In the MySQL database, a transaction is a set of SQL statements. Either all executions are successful or all executions fail, ensuring the consistency and integrity of the data. In MySQL, transactions can be divided into automatic submission and manual submission. The difference lies in the timing of transaction submission and the scope of control over the transaction. The following will introduce the difference between automatic submission and manual submission in detail, and give specific code examples to illustrate. 1. Automatically submit in MySQL, if it is not displayed

Detailed explanation of the meaning of MySQL host name Detailed explanation of the meaning of MySQL host name Mar 01, 2024 pm 12:03 PM

The meaning and specific usage of MySQL host name MySQL is a popular open source relational database management system that is widely used in various web applications. In MySQL, hostname is an important concept, which is used to specify the name of the host connected to the database server. In this article, we will explain in detail what the MySQL hostname means and how to use it in actual development. The meaning of MySQL host name: In MySQL, the host name is used to specify which connections are allowed to

bottom attribute syntax in CSS bottom attribute syntax in CSS Feb 21, 2024 pm 03:30 PM

Bottom attribute syntax and code examples in CSS In CSS, the bottom attribute is used to specify the distance between an element and the bottom of the container. It controls the position of an element relative to the bottom of its parent element. The syntax of the bottom attribute is as follows: element{bottom:value;} where element represents the element to which the style is to be applied, and value represents the bottom value to be set. value can be a specific length value, such as pixels

Introduction to the attributes of Hearthstone's Despair Thread Introduction to the attributes of Hearthstone's Despair Thread Mar 20, 2024 pm 10:36 PM

Thread of Despair is a rare card in Blizzard Entertainment's masterpiece "Hearthstone" and has a chance to be obtained in the "Wizbane's Workshop" card pack. Can consume 100/400 arcane dust points to synthesize the normal/gold version. Introduction to the attributes of Hearthstone's Thread of Despair: It can be obtained in Wizbane's workshop card pack with a chance, or it can also be synthesized through arcane dust. Rarity: Rare Type: Spell Class: Death Knight Mana: 1 Effect: Gives all minions a Deathrattle: Deals 1 damage to all minions

See all articles