Sql 随机更新一条数据返回更新数据的ID编号

DECLARE @parimaryTable(临时表)  Table(prizecode varchar(50));
update top (1)  数据表 set 字段a='数值' ,字段b=‘数值’ output deleted.prizecode into @parimaryTable(临时表)  where  条件字段    ; select * from @parimaryTable

样例

public string GetUserPrizeChangeListRamdom(string customerId, int userid)
{
if (!customerId.Equals(""))
using (var db = new SqlServer())
{
var updateSql = string.Format(@"DECLARE @parimaryTable Table(prizecode varchar(50));
update top (1) UserPrizeChangeList set consumerid='{0}' ,userid={1},status=1,usetime=getdate() output deleted.prizecode into @parimaryTable where status=0 ; select * from @parimaryTable", db.InjectReplace(customerId), userid);
return db.GetScalar<string>(updateSql);
}
else
return null;
}
上一篇:svn版本控制-windows篇


下一篇:2018-2019-2 网络对抗技术 20165202 Exp4 恶意代码分析