首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-01-24 
请问一个简单的SQL语句或则存储过程,来者有分。有一个表WList,字段有ID:自动编号,URL:string,Title:string,

请问一个简单的SQL语句或则存储过程,来者有分。
有一个表WList,字段有ID:自动编号,URL:string,Title:string,IsUpdate:bit.
如何用一个SQL语句或则存储过程实现如下功能:
更新第一条IsUpdate=false的记录为true,并且返回这条数据信息。
(注意数据可能还有其他人在访问,尽量更新和取这条数据的时候锁定这条记录不被别人更新和查询到)

[解决办法]
一个存储过程即可。
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
[解决办法]
update WList
set IsUpdate = true
from WList a,
(select top 1 * from WList where IsUpdate = false) b
where a.id = b.id
[解决办法]
乌龟兄,言之有理。
[解决办法]
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
[解决办法]
update WList
set IsUpdate = true
from WList a,
(select top 1 * from WList where IsUpdate = false) b
where a.id = b.id

热点排行