ASP查询SQLSERVER的问题
Hotus 2019-09-05 10:06:19 现在有两个表
ID UserID
1 111
ID UserID
想实现的是多线程从表1查询出不在表2中的数据,并插入到表2中并输出结果
只有1条数据或者数据量很少的情况下,多线程访问ASP执行下面的代码,可能会同时返回几条相同的数据
主要是因为查询出来的数据还没插入到List2,又被其他线程查询到了
有没有办法rs查询的时候,将查询的数据锁定,不让其他线程再查询到呢
rs.open "select top 1 * FROM List1 A where (not exists(select top 1 UserID from List2 B where B.UserID=A.UserID order by newid()", conn,1,3
if not rs.eof then
rs2.open "select * from List2 where UserID='"&rs("UserID")&"'", conn,1,3
if rs2.eof then
rs2.addnew
rs2("UserID")=rs("UserID")
rs2.update
end if
response.write rs("UserID") '多线程的情况下这里可能会有几个线程同时查询到这一条记录
rs2.close
end if
rs.close