请问一个简单的SQL语句或则存储过程,来者有分。

yzty 2007-10-07 10:07:52
有一个表WList,字段有ID:自动编号,URL:string,Title:string,IsUpdate:bit.
如何用一个SQL语句或则存储过程实现如下功能:
更新第一条IsUpdate=false的记录为true,并且返回这条数据信息。
(注意数据可能还有其他人在访问,尽量更新和取这条数据的时候锁定这条记录不被别人更新和查询到)
...全文
132 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
晓风残月0110 2007-10-08
  • 打赏
  • 举报
回复
update WList
set IsUpdate = true
from WList a,
(select top 1 * from WList where IsUpdate = false) b
where a.id = b.id
cataclyam2000 2007-10-08
  • 打赏
  • 举报
回复
select top 1 * from WList where IsUpdate = false

update WList
set IsUpdate = true
from WList a,
(select top 1 * from WList where IsUpdate = false) b
where a.id = b.id
yzty 2007-10-08
  • 打赏
  • 举报
回复
还必须返回这条记录??
  • 打赏
  • 举报
回复
乌龟兄,言之有理。
dawugui 2007-10-07
  • 打赏
  • 举报
回复
update WList
set IsUpdate = true
from WList a,
(select top 1 * from WList where IsUpdate = false) b
where a.id = b.id
  • 打赏
  • 举报
回复
一个存储过程即可。
Create P_UPFlag
as
begin Tran
Declare @id int
select @id=min(id) from Wlist where isupdate=false
update WList set isupdate=ture where id=@id
select * from Wlist where id=@id
commit Tran

34,593

社区成员

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

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