How to change column datatype in SQL database without losing data

前端 未结 11 2598
迷失自我
迷失自我 2020-12-02 06:55

I have SQL Server database and I just realized that I can change the type of one of the columns from int to bool.

How can I do that withou

11条回答
  •  我在风中等你
    2020-12-02 07:08

    for me , in sql server 2016, I do it like this

    *To rename column Column1 to column2

    EXEC sp_rename 'dbo.T_Table1.Column1', 'Column2', 'COLUMN'
    

    *To modify column Type from string to int:( Please be sure that data are in the correct format)

    ALTER TABLE dbo.T_Table1 ALTER COLUMN Column2  int; 
    

提交回复
热议问题