Vig*_*h M 2 sql-server performance sql-update
看下面的代码,
Create table #test
(
id int primary key,
Name varchar(100)
)
insert into #test values (1,'John')
insert into #test values (2,'Walker')
insert into #test values (3,'Bob')
insert into #test values (4,'Tailor')
insert into #test values (5,'Phlip')
insert into #test values (6,'Kevin')
-- Query 1 :
update #test set name = 'Joney' where id = 1
-- Query 2 :
set rowcount 1
update #test set name = 'Joney' where id = 1
set rowcount 0
Run Code Online (Sandbox Code Playgroud)
提前致谢
在查询1中,即使找到1行,sql服务器是否会查找匹配的行?
不知道它知道它是一个主键,它将在内部查看称为B +树的数据结构并找出该记录的位置.
查询2真的会获得一些性能吗?
不.它没有任何区别,但增加了开销.