您的位置:首页 > 其它

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

2008-12-10 09:18 239 查看
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,1) as ID, * into tb from tableName


select * from tb
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: