把一个表添加了新的列后,怎么在程序中给添加信息? model层是之前没添加新列的表,怎么写inert语句?

解决方案 »

  1.   

    --1.可以用update
    --2.把原表存到临时表,删除原表,加入新列值一并插入表。
      

  2.   

     生成了新表后 我再添加的话该怎么写需要执行的sql语句呢?
      

  3.   

    --1.统一将新列更新为某值:
    update model set newcol='某值' --where 可加条件--2.新列值来源于另一个表的更新:
    update a set a.newcol=b.col
    from model a 
      join othertb b
        on a.id=b.id
      

  4.   

    create proc p_insert_model 
    @id int,--指定原表ID
    @value varchar(100) --输入要更新的值
    AS
    update model set 
        newcol=@value  
    where id=@id
    GO参考
      

  5.   

     表的ID?是整个表的ID 还是表中的一列ID?