请教一个问题,数据库有1万条数据,我想在某一字段前面都加上字母A,比如100,200,300......10000,更改后就是A100,A200,A300......A10000

解决方案 »

  1.   

    --如果列是字符型的
    update tablename set colname='A'+colname
    --如果列是int型的,存不进去A,需要改成varchar或是nvarchar
      

  2.   


    colname这个值怎么得来的呢
      

  3.   


    declare @t table (id varchar(10))
    insert into @t
    select 1 union all
    select 2 union all
    select 3 union all
    select 4 union all
    select 5update @t set id='A'+id
    select * from @t
    /*
    id
    ----------
    A1
    A2
    A3
    A4
    A5
    */
      

  4.   

    不用where  那不是每一列都是一样的了哦
      

  5.   


    表cxlh100
    101
    102
    103
    .
    .
    .
    1000000改后
    A100
    A101
    A102
    A103
    .
    .
    .
    A10000
      

  6.   

    如果xlh字段是char nchar varchar nvarchar类型的
    update 表c set xlh='A'+xlh 即可。
      

  7.   


    --创建一个表
    create table 表c(xlh varchar(10))
    insert into 表c
    select 1 union all
    select 2 union all
    select 3 union all
    select 4 union all
    select 5 union all
    select 1000--查看表中数据
    select * from 表c
    /*
    xlh
    ----------
    1
    2
    3
    4
    5
    1000
    */
    --添加一个列
    alter table 表c add nid varchar(20)--更新数据
    update 表c set nid='A'+xlh--查看更新后的结果
    select nid from 表c
    /*
    nid
    --------------------
    A1
    A2
    A3
    A4
    A5
    A1000
    */
      

  8.   


    楼主问你怎么解决。回答跟没回答一样 搞笑!update t_menu t set t.moduleid=concat('A',t.moduleid)
    如果需要加上条件的话 
    update t_menu t set t.moduleid=concat('A',t.moduleid) where length(t.moduleid)=1;