有一表"table1"如下
id daa fid
1 561
2 564
3 451
4 454我想在“fid”列中从3开始,自增+1的序号填充“fid”列。结果如下:id daa fid
1 561 3
2 564 4
3 451 5
4 454 6

解决方案 »

  1.   

    创建表吗?定义 fid as id + 2即可.
      

  2.   

    如果是更改表数据.update tb set fid = id + 2
      

  3.   

    create table tb(id int,aaa varchar(100),fid as id+2)
      

  4.   


    如果id不连续;with cte as 
    (
    select idx=row_number() over(order by id ),* from tb
    )
    update cte set fid=idx+2;
      

  5.   

    实时更新有3种办法:
    1.建立一个试图
    2.计算列
    3.触发器更新一次:
    update tb set fid = id + 2
      

  6.   


    update tb set fid = id + 2
      

  7.   

    Create table tb(
     id int identity(1,1),
     name varchar(20)
    )
    GO
    insert into tb
    select '2' union all
    select '3' union all
    select '4'select id,name,ROW = ROW_NUMBER() over(order by id asc) + 2
    from tb