其中,aaa、bbb、ccc为表中字段,而:1、2、3、4.....是人为添加的递增数列
[/Quote]
--方法一
select id = identity(int,1,1) , * into tmp from tb
select * from tb
--方法二
select id = (select count(1) from tb where aaa < t.aaa) + 1 from tb t
--方法三
select id = (select count(1) from tb where aaa < t.aaa or (aaa = t.aaa and bbb < t.bbb) or (aaa = t.aaa and bbb = t.bbb and ccc < t.ccc)) + 1 from tb t
--方法四(sql server 2005)
select id = row_number() over(order by aaa , bbb, ccc) , * from tb