The fastest way to change the column data type in SQL Server

In SQL Server 2008, I have a table with about 3 million records. I want to change the type of one of my columns from float to int. But it looks like it will take a long time. Is there any way to do this very fast?

+3
source share
5 answers

Drop any constraints, indexes, and triggers for this table; they also slow down the update.

+2
source

Add a new int column to the table, update the new column to the value of the old column, delete the old column, rename the new column.

I have a feeling that it will be faster, but I could be wrong!

, float, .

+2

" " .

, , .

+1

, , SSMS . . , SSMS -, , .

0

The ALTER table is usually faster than using SSMS. In any case, I agree with doogstar, since you need to convert all the data to int, I would create a new column to populate it (which you can do in batches to improve performance and prevent table locking), then discard the old column and rename new.

0
source

Source: https://habr.com/ru/post/1728171/


All Articles