use pubs
select city into #temp from dbo.authors order by 1
select identity(int,1,1) as id,city into #T from #temp
select * from #t
select city into #temp from dbo.authors order by 1
select identity(int,1,1) as id,city into #T from #temp
select * from #t
insert into tab values('AAA')
insert into tab values('BBB')
insert into tab values('CCC')
select col,(select count(t2.col)+1 from tab t2 where t2.col<t1.col) as id
from tab t1
order by col
注意:此列(此处为col)不能有重复!