生成按某个字段排序后的序列号

来源:互联网 发布:新闻出版网络教育系统 编辑:程序博客网 时间:2024/06/05 20:16

Sql Server 2005:

 

select row_number() (order by col) as id, * from tablename

 

非Sql Server 2005:

select (select count(*from tablename b where a.col <= b.col) as ID, a.* from tablename a order by a.col

 若表中没有自动增长的列:

 

select IDENTITY(1,1as ID, * into tb from tableName
select * from tb
原创粉丝点击