用T-SQL语句 自动生成序号 排序

方式一(用row_number() 函数):

select top 10 row_number() over (order by name) as rowid, sysobjects.[name] from sysobjects 

order by name desc

 

方式二(创建临时表):

if exists (select 1 from sysobjects where name ='table_temp' and type ='U')

drop table table_temp

 

select top 10 id=IDENTITY(int,1,1), sysobjects.[name] as name into table_temp 

from sysobjects

order by name desc

 

select * from table_temp

你可能感兴趣的:(SQL,Server)