zoukankan      html  css  js  c++  java
  • 数据库排序事务

    最近在整理文档:之前不知道在哪里看到的转过来,收藏之供大家学习之用。

    select   *   from   表格   where   是否置顶=True   Order  by   ID   Desc "
    select   *   from   table   order   by   是否置顶,自动编号   desc
    select   *   from   [info]   order   by   是否置顶   desc,发表时间   desc

    -------向上移
    select   *   from   Forum   order   by   _order   desc
    go
    begin transaction
          declare @errorsum int
          set @errorsum=0
          declare @param int
          set @paramId=0
          update Forum set _order=@paramId-1 where _order=@paramId
          @errorsum=@errorsum+@@error
          update Forum set _order=14 where _order=@paramId-1
          @errorsum=@errorsum+@@error
          if @errorsum=0
               commit transaction
         else
              rollback transaction
     go
    select   *   from   Forum   order   by   _order   desc
    -------向下移
    select   *   from   Forum   order   by   _order   desc
    go
       begin transaction
           declare @errorsum int
           set @errorsum=0
           declare @param int
           set @paramId=0
           update Forum set _order=@paramId+1 where _order=@paramId
           @errorsum=@errorsum+@@error
           update Forum set _order=@paramId where _order=@paramId+1
           @errorsum=@errorsum+@@error
          if @errorsum=0
               commit transaction
          else
               rollback transaction
    go
    select   *   from   Forum   order   by   _order   desc
    备注:事务是一件必须完成的事通过步骤完成。

  • 相关阅读:
    四则运算(web)
    二维数组
    java (数组)
    GitHub
    PSP(第四周)
    四则运算三
    PSP表(第三周)
    软件需求阅读笔记02
    软件需求阅读笔记01
    Android开发进度06
  • 原文地址:https://www.cnblogs.com/boonya/p/2754089.html
Copyright © 2011-2022 走看看