请教一个问题。

neverwin 2004-04-30 12:33:12
现在有一张临时表A,不断执行插入(理想情况)
同时要求定时提取数据,插入另一张表,然后删除临时表A中相应的纪录。
虽然从A提取和删除纪录是两条连续的语句,或者把他们放到一个存储过程中去。
那么在提取和删除的间隔时间,会不会有新的数据插入?
如果有,怎么解决才好呢?
谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!
...全文
58 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
neverwin 2004-04-30
  • 打赏
  • 举报
回复
感谢回答!!
netcoder(正当商人) :
锁住表?会不会影响往临时表插入呢?
我去44,行了马上揭帖

zheninchangjiang(我爱燕子):
我想等临时表数据到一定程度再操作,用触发器来一条就操作太实时了

再次感谢!

judicainiao 2004-04-30
  • 打赏
  • 举报
回复
学习ing
zheninchangjiang 2004-04-30
  • 打赏
  • 举报
回复
做触发器
你的临表时应该是在数据库中的吧
netcoder 2004-04-30
  • 打赏
  • 举报
回复
用锁锁住
select * from #表 holdlock
neverwin 2004-04-30
  • 打赏
  • 举报
回复
消化中.先揭帖
zjcxc 元老 2004-04-30
  • 打赏
  • 举报
回复
加标志字段处理,和这个的处理差不多.

--处理示例
http://expert.csdn.net/Expert/topic/2921/2921334.xml?temp=.2235376

--在表中增加几个字段:
read_time --读取记录的时间
host_name --读取记录的电脑名称
read_user --读取记录的操作员


--在 CSDNM 的基础上修改(结合两种方法)后的示例

create proc 提取记录
@read_user char(20) ---审核者
as
declare @id int

BEGIN TRANSACTION
--从本机,本人读取的记录中取
select top 1 @id=id from tablename with (UPDLOCK)
where 某字段=2
and [host_name]=host_name()
and read_user=@read_user
order by time

if @@rowcount=0 --如果没有,从没有被读取的记录中读取
begin
select top 1 @id=id from tablename with (UPDLOCK)
where 某字段=2
and(host_name is null
or read_user is null)
order by time

if @@rowcount=0 --如果没有,从超时的记录中读取
begin
select top 1 @id=id from tablename with (UPDLOCK)
where 某字段=2
and read_time<datediff(hout,-1,getdate()) --假设超时时间为1小时
order by time

if @@rowcount=0 --无记录退出
begin
commit tran
return
end
end
end

update tablename set
read_user=@read_user,
[host_name]=host_name(),
read_time=@read_time
where id=@id
commit transaction
select * from tablename where id=@id
go


34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧