不好意思,刚看到你的帖子,我做了一个实验是可以的:
--1.建表,插入数据
--drop table t
create table t
(
id int ,
name varchar(100),
vname varchar(100)
constraint pk_t_id_name primary key clustered(id,name)
)insert into t
select object_id,name,name
from sys.objects
--2.修改之前的数据
select *
from t
where id = 167671645
/*
id name vname
167671645 Prods Prods
*/
--3.更新-行锁,没有报错
update t with(rowlock)
set vname ='abc'
where id ='167671645' and vname = 'Prods'
/*
(1 行受影响)
*/
--4.更新之后的数据
select *
from t
where id = 167671645
/*
id name vname
167671645 Prods abc
*/
--1.建表,插入数据
--drop table t
create table t
(
id int ,
name varchar(100),
vname varchar(100)
constraint pk_t_id_name primary key clustered(id,name)
)insert into t
select object_id,name,name
from sys.objects
--2.修改之前的数据
select *
from t
where id = 167671645
/*
id name vname
167671645 Prods Prods
*/
--3.更新-行锁,没有报错
update t with(rowlock)
set vname ='abc'
where id ='167671645' and vname = 'Prods'
/*
(1 行受影响)
*/
--4.更新之后的数据
select *
from t
where id = 167671645
/*
id name vname
167671645 Prods abc
*/
index_id,
type_desc,
allow_row_locks
from sys.indexes
where object_id = object_id('t')
/*
name index_id type_desc allow_row_locks
pk_t_id_name 1 CLUSTERED 1
*/
进一步的,通过如下的语句,可以修改索引 是否允许 row lock:alter index pk_t_id_name on t
set (ALLOW_ROW_LOCKS = on)那么,对应到你的表,就是这样:alter index 索引名称 on studentranks
set (ALLOW_ROW_LOCKS = on)