这个存储过程每分钟执行一次单线程(A表中除了插入还有修改[count] = 3 的都是多线程。)
功能:就是将A 表[count] > 2 的数据备份到B表,并将A表中已备份的数据删除掉,
但是有时候A表的一条数据会在B表中备份多条(那个数据在A表中确实就一条),还有我看B表中插入时间都是相隔几毫 秒说明都是一次插入的,
我不明白为什么会出现这种情况
select distinct [id] into #A_temp from A where [count] > 2;
//判断是否有数据
if exists(select [id] from #A_temp)
begin
/**将已发送的记录导入到备份表中**/
insert into
B(
col1,
col2
)
select
col1,col2
from
A with(nolock)
where
[id] in (select [id] from #A_temp);
/**将已发送的记录导入到备份表中**/
--删除已备份的记录
delete from A where [id] in (select [id] from #A_temp);
end