例如:select * from users查询出来的结果为:
uesr1
user2
user3
如何增加一列数字编号即:
1,uesr1
2,user2
3,user3

解决方案 »

  1.   

    select ID=identity(int, 1, 1), * into #T from usersselect * from #T
      

  2.   

    select (select count(*) from users where name<=u.name) as id,u.name from users u order by id
      

  3.   

    select id=identity(int,1,1),* into tb from users
    select * from tb drop table tb
      

  4.   

    create table users(col1 nvarchar(20))
    insert users select 'user1'
    insert users select 'user2'
    insert users select 'user3'select ID=identity(int, 1, 1), * into #T from usersselect * from #T--result
    ID          col1                 
    ----------- -------------------- 
    1           user1
    2           user2
    3           user3
      

  5.   

    identity(int, 1,1)
    插入连续的序号
      

  6.   

    libin_ftsafe(子陌红尘:当libin告别ftsafe)的还不错,数据量大的话效率是个问题
      

  7.   

    那你用ORACLE好了,SQL2K只能这么做
      

  8.   

    还是marco08(天道酬勤) 的办法稳一点,如果你的user字段有重复值的话,子陌的会有点问题