自增列(identity)是可能重复的喔,如下测试,建议检查确认一下.-- 建测试表 create table LR(LRId int not null identity(1,1)) -- 插入2条重复LRId的记录 set identity_insert LR oninsert into LR(LRId) select 101insert into LR(LRId) select 101set identity_insert LR off -- 检查重复 select LRId, count(1) 'qty' from LR group by LRId having count(1)>1/* LRId qty ----------- ----------- 101 2(1 row(s) affected) */
不太相信你的in内部的Select语句搜索记录为0条时,外围的Select仍旧为39条数据~
而且也要看你的连接条件是不是1对1的 如果不是也有可能导致。
"in内部的Select单独执行时,搜索出9条LRId。" --> 符合子查询where子句诸多条件的LRId有9个.
"整个Select执行时,搜索出39条记录" --> 当LR表LRId字段的数据不是唯一时,同个LRId可能对应多笔记录,所以2个数量没有可比性.
LRId不会重复的,是自动增长列
晕死,刚刚在家又试了,结果符合预期,没有出现39条记录的问题。
SQL语句肯定没问题,从单位电脑复制到CSDN,再从CSDN复制到家里电脑。
为了这个事情,周五我在办公室从5点半弄到6点半没搞定,是不是单位电脑的企业管理器有问题?晕死。
create table LR(LRId int not null identity(1,1))
-- 插入2条重复LRId的记录
set identity_insert LR oninsert into LR(LRId) select 101insert into LR(LRId) select 101set identity_insert LR off
-- 检查重复
select LRId,
count(1) 'qty'
from LR
group by LRId
having count(1)>1/*
LRId qty
----------- -----------
101 2(1 row(s) affected)
*/