表中结构是这样:Id,Sorce
1,1
2,2
3,2
.
.
.
新增一列,要求新增列Sorce的值 是当前表中最大的Sorce值加一

解决方案 »

  1.   

    insert into tb (Sorce) values((select max(Sorce) from tb)+1)
      

  2.   

    问题是我不会用sql语句新增一列啊,我只会拆下来写。我想合起来一起写。Insert into tb(id,score) values(id,select max(score) from tb +1) 像这种样子的,但是我写的格式不对
      

  3.   

    新增一列?列名叫什么
    如果是新增一条记录   
    insert into tablename values ((select max(id) from @tabel)+1,(select max(sorce) from tabelname)+1 )
      

  4.   

       string sql = "insert into ProductCategory (CategoryName,Description,SortIndex,CreateUserId) values('"+categoryName+"','"+Description+"',
                    '"+select max(SortIndex) from ProductCategory where ParentId is null)+1+"','"+UserID+"')";
    可是我这样写不对啊
      

  5.   

                    string sql = "insert into ProductCategory (CategoryName,Description,SortIndex,CreateUserId) values('"+categoryName+"','"+Description+"',
                    'select max(SortIndex) from ProductCategory where ParentId is null)+1', '"+UserID+"')";这样写也不对,
      

  6.   


    alter table tb add[max_sorce] int
    update tb set max_sorce=((select max(sorce) from tb)+1)