How to change a column without dropping a table in SQL 2008

前端 未结 5 364
执笔经年
执笔经年 2021-01-31 02:01

Why does SQL 2008 all of a sudden want to drop my tables when I go to change the column type from say int to real? This never happened in SQL 2005 to my knowledge. Any insight

5条回答
  •  时光说笑
    2021-01-31 02:58

    Another way to this without totally dropping the table is

    1. Take a backup of the column values.
    2. Make the column nullable if it does not already allow nulls. Set the column values to be null by doing

      update tablename set columnname = null 
      
    3. Delete the column
    4. Insert a new column with the same name as the deleted column and the type which you want
    5. Insert the saved data into this column

提交回复
热议问题