好好学习,天天向上

--每天都有好心情
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

查询语句中添加自动编号

Posted on 2007-05-08 19:30  凤麟  阅读(222)  评论(0)    收藏  举报
使用sql语句:
  1、使用一条sql语句,原理是在结果中查询大于等于该记录的记录跳数。如:select count(*) as Rank,a1.urlname from urlconfig a1,urlconfig a2 where a1.urlname>a2.urlname
      group by a1.urlname order by Rank 。缺点:性能不好;如果存在相同记录,就会出现并列情况。
  2、sql提供了identity function,可以获得标识列的值,不过这个函数只能用于select into语句,所以需要引入临时表
     select identity(int,100,1)as rank,urlname into #tmp from urlconfig select * from #tmp drop table #tmp
     drop table #tmp这种方法性能和适用性都比第一种方法号,缺点是必须通过几条sql语句才能完成。一般还是建议在客户端完成。