Lock (3) -- Update lock (U) and exclusive lock (X)

Source: Internet
Author: User

The following articles detail the distribution of update locks and exclusive locks during the update operation.

Http://blog.csdn.net/zjcxc/article/details/27351779

According to the tracing method described in the above article, we found that in the article lock (2) -- in the process of creating and updating tables, we use sys. the results of the dm_tran_locks dynamic view are the final locking results, but the changes in the locks are not reflected. If you want to know the lock changes in detail, you can still use the profile method.

In order to enhance my impression and understanding, I will test myself again:

-- This process is 64. first create a table and initialize five data records, and then update the data in the transaction create table dbo. TB (C1 int, C2 char (10), C3 varchar (10); godeclare @ ID int; Set @ ID = 0; while @ ID <5 begin; set @ ID = @ ID + 1; insert DBO. TB values (@ ID, 'B' + right (10000 + @ ID, 4), 'C' + right (100000 + @ ID, 4); end; begin tranupdate DBO. TB set C2 = 'xx' where c1 = 2; waitfor delay '00: 00: 30'; update DBO. TB set C2 = 'xx' where c1 = 5; -- rollback;
-- Process 66: Start a transaction and update a record in the TB table begin tranupdate DBO. TB set C2 = 'xx' where c1 = 1; rollback;

The tracing in profile is as follows:

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.