【发布时间】:2019-02-26 05:20:24
【问题描述】:
delete from summary
Declare @rows int
set @rows=0
while @rows <29000
begin
insert into Summary
select * from table a full join table b on
ID = ID
where pk is not null
end
我尝试运行上面的代码,但它一直在不停地运行,当我最终停止它时,它给出了以下结果:
(28029 行受影响)
(28029 行受影响) 消息 2627,第 14 层,状态 1,第 13 行 违反 PRIMARY KEY 约束“PK_Summary”。无法在对象“dbo.Summary”中插入重复键。 声明已终止。
然后我认为这是 PK 问题,所以我从表中删除了所有内容,只运行插入语句而不使用 while 循环,它可以工作。所以我猜测还有其他问题,但我不知道它是什么。其他人可以为我指出吗?而且我已经验证了表中只有 28K+ 行。
【问题讨论】:
-
我没有看到你增加了
@rows,所以@rows将永远小于 29000
标签: sql while-loop