我已有一张表,里面有很多数据现在我想加一个字段,对原来数据进行编号请问该如何实现

解决方案 »

  1.   

    -- 如果对编号没有要求, 直接用自增列就行了
    ALTER TABLE 你的表
        ADD 编号 int IDENTITY
      

  2.   


    -- 如果对编号没有要求, 直接用自增列就行了
    ALTER TABLE 你的表
        ADD 编号 int IDENTITY
    简单的旧这样
      

  3.   


    create table tb(name varchar(10))
    insert tb
    select 'f' union all
    select 'b' union all
    select 'g' union all
    select 'h' select * from tb
    /*
    name       
    ---------- 
    f
    b
    g
    h
    */
    alter table tb add [id] int identity
    select * from tb
    /*
    name       id          
    ---------- ----------- 
    f          1
    b          2
    g          3
    h          4
    */
    drop table tb
      

  4.   

    解决了?那我接分.
    除了IDENTITY,加个字段后按某种你需要的排序号也可.如:select * , px = (select count(1) from tb where id < t.id) + 1 from tb t
      

  5.   

    select * , px = (select count(1) from tb where id < t.id) + 1 from tb t