tags:

views:

186

answers:

2

Hi, I am tasked with changing a table's column datatype from smallint to int for a table that has 32 million rows in it. The requirement is to have the lowest downtime possible (basically the fastest way of achieving this). We are using SQL Server 2000.

Please help!

+4  A: 

There are a couple options, you could make an online copy of the table and then use sp_rename to switch it out.

Another way is to add a new column, populate it, then drop the old column and rename the new column.

32m rows could be considered big or small depending on the width of the row.

Cade Roux
I am pretty confident that benchmarking would show that sp_rename would be the lowest-downtime option
Tetsujin no Oni
The sp_rename would be quick, but the table copy might take a very long time if the rows are wide, so you might need to run an update on the destination table before the sp_rename. In the in situ version, you could populate and update any changed rows and then do the rename on the column. I guess, it really depends on what is considered downtime and what is the rest of the maintenance window which will completely depend on how much activity is happening on the table.
Cade Roux
+1  A: 

Whatever you do, do not use Enterprise Manager to change the datatype. What it will do is create a whole new table, populate it, rename the old table, rename the new table to the old table's name and drop it all in one nasty transaction locking the table for hours.

HLGEM