select identity(int,1,1) as XH, * into #t from users go select * from #t order by XH go
select (select count(*) from users where TID <= A.TID) as XH, * from users as A order by TID
alter table users add rownum int identity(1,1) select * from users alter table users drop column rownum
ALERT TABLE USER ADD ID INT IDENTITY(1,1) SELECT * FROM USER
如果TID已经是标识列 那么用登山的这个方法 select (select count(*) from users where TID <= A.TID) as XH, * from users as A order by TID
没有主键的情况: select identity(int,1,1) as XH, * into #t from users go select * from #t order by XH go 有主键的情况: select (select count(*) from users where TID <= A.TID) as XH, * from users as A order by TID
go
select * from #t order by XH
go
order by TID
select * from users
alter table users drop column rownum
SELECT * FROM USER
那么用登山的这个方法
select (select count(*) from users where TID <= A.TID) as XH, * from users as A
order by TID
select identity(int,1,1) as XH, * into #t from users
go
select * from #t order by XH
go
有主键的情况:
select (select count(*) from users where TID <= A.TID) as XH, * from users as A
order by TID