惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
O
OpenAI News
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
Project Zero
Project Zero
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Tor Project blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
Spread Privacy
Spread Privacy
Cisco Talos Blog
Cisco Talos Blog
T
Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
Cloudbric
Cloudbric
I
Intezer
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
AI
AI
B
Blog
S
Securelist
P
Proofpoint News Feed
量子位
Jina AI
Jina AI
V2EX - 技术
V2EX - 技术
T
The Exploit Database - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
CERT Recently Published Vulnerability Notes
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 楚潇

基于dotnet2.0的联通sgip1.2协议二级网关源码 .net winform下TreeNode在没有子结点时也显示+号的解决办法 在vs2005中用gridview显示表中的image字段 - 楚潇 - 博客园 谁没在变! vs2k5 中asp.net "Web Site Administration Tool "使用中遇到的问题 - 楚潇 美达飞凡16X DVD起死回生记 寄语八十年代的新一代 小胜凭智, 大胜靠德 《windows核心编程》 再读<心航> visual C# 2005 express beta2读配置文件的问题(ms的bug?) C#中判断socket是否已断开的方法 将对象转为byte[] 摘自古龙的句子 端午节到了 C#中的字符串格式化 .net开发手机短信 怎样才能提高.net的水平呢? Reflaction很嚣张的功能
有关sqlserver的锁
楚潇 · 2008-07-10 · via 博客园 - 楚潇

今天有被问到:sqlserver锁定一行的最小锁是什么?
当时答曰:行级锁

回来查文档,得有关锁的信息(sql2k用syslockinfo表查, sql2k5用sys.

dm_tran_locks表查)

资源类型:
1 = NULL 资源(未使用)
2 = 数据库
3 = 文件
4 = 索引
5 = 表
6 = 页
7 = 键
8 = 区
9 = RID(行 ID)
10 = 应用程序

OK,现在来看看锁定到一行的最小级别的锁是什么。

 1D:\Program Files\Microsoft SQL Server\90\Tools\Binn>osql -Usa -Pdba123 -Sdragon
 21> create table t_pk(t_id int primary key, t_desc varchar(50));
 32> create table t_heap(t_id int, t_desc varchar(50));
 43> go
 51> insert into t_pk values(1'welcome');
 62> insert into t_pk values(2'nice to meet you');
 73> insert into t_pk values(3'wall street, stock');
 84> go
 9(1 行受影响)
10(1 行受影响)
11(1 行受影响)
121> insert into t_heap select * from t_pk;
132> go
14(3 行受影响)
151> begin tran
162> update t_pk set t_desc = 'have a nice day' where t_id = 3;
173> go
18(1 行受影响)
19


现在,我更新有主键的表t_pk,看看sqlserver锁了些什么东东:

这里,sqlserver对t_pk表以及相应的page加上了IX锁,对更新的那一行加上了X锁。

再来,现在试试对堆表的更新:

1> rollback;
2> go
1> begin tran
2> update t_heap set t_desc = 'have a nice day' where t_id = 3;
3> go

看看sqlserver对堆表锁了些什么:

sqlserver 2005很聪明,也只锁了一行(曾记得,sql2k对堆表会锁住一个page的,待找sql2k再测试)。

这2个测试中的锁定,一个是KEY, 一个是RID, 基本符合我所说的行级锁的意思。但真较上劲的话,我的答案又似乎不足,:)