在UPDATE中更新TOP条数据以及UPDATE更新中使用ORDER BY

2016-12-23 11:32:14来源:cnblogs.com作者:流空.NET人点击

正常查询语句中TOP的运用:SELECT TOP 1000 *FROM MP_MemberGrade 随意更新一张表中满足条件的前N条数据:UPDATE TOP (1) MP_Member SET FKGradeID=2WHERE IsDeleted=2 更新A表中满足B表前N条记录的数据UPDATE MP_Member SET FKGradeID=2FROM MP_Member ALEFT JOIN (SELECT TOP 10 * FROM MP_MemberGrade WHERE IsDeleted=2) B ON A.FKGradeID=B.PKIDWHERE A.IsDeleted=2UPDATE MP_Member SET FKGradeID=4FROM (SELECT TOP 10 * FROM MP_MemberGrade WHERE IsDeleted=2) BWHERE MP_Member.IsDeleted=2 AND FKGradeID=B.PKID UPDATE更新中使用ORDER BYUPDATE MP_Member SET FKGradeID=2FROM MP_Member ALEFT JOIN (SELECT TOP 10 * FROM MP_MemberGrade WHERE IsDeleted=2 ORDER BY PKID DESC) B ON A.FKGradeID=B.PKIDWHERE A.IsDeleted=2ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效,除非另外还指定了 TOP 或 FOR XML。 

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台