select id=row_number()over(order by getdate()),* from tb
select id1=(select count(1) from @tb where id<a.id)+1 , * from @tb a
declare @tb table(id int,name varchar(50)) insert into @Tb select 1,'王' insert into @Tb select 4,'李' insert into @Tb select 6,'黄' select *,row_number() over(order by id) as id2 from @tb id name id2 1 王 1 4 李 2 6 黄 3
--2000select id=(select count(1)+1 from TB where id<t.id),* from TB t
--> 测试数据:@tb declare @tb table([id] int,[name] varchar(2)) insert @tb select 1,'王' union all select 4,'李' union all select 6,'黄'select id1=(select count(1) from @tb where id<a.id)+1 , * from @tb a id1 id name ----------- ----------- ---- 1 1 王 2 4 李 3 6 黄(3 行受影响)
id=row_number()over(order by getdate()),*
from
tb
insert into @Tb select 1,'王'
insert into @Tb select 4,'李'
insert into @Tb select 6,'黄'
select *,row_number() over(order by id) as id2
from @tb
id name id2
1 王 1
4 李 2
6 黄 3
id=(select count(1)+1 from TB where id<t.id),*
from
TB t
declare @tb table([id] int,[name] varchar(2))
insert @tb
select 1,'王' union all
select 4,'李' union all
select 6,'黄'select id1=(select count(1) from @tb where id<a.id)+1 , * from @tb a
id1 id name
----------- ----------- ----
1 1 王
2 4 李
3 6 黄(3 行受影响)