最近在整理文档:之前不知道在哪里看到的转过来,收藏之供大家学习之用。
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
备注:事务是一件必须完成的事通过步骤完成。