Long live,
There are some solutions to this problem:
1 - Hammering (Not tested)
You can temporarily change the table name, create a view with the table name you previously had with WITH(NOLOCK) and update the table. After UPDATE runs, you delete the VIEW and re-name the table to the original name.
2 - Instalments UPDATES
Instead of doing UPDATE to the entire table at once, you can/should do smaller updates.
UPDATE TOP(1000) tabela SET enviado = 1 WHERE enviado is null
WHILE @@rowcount > 0
BEGIN
UPDATE TOP(1000) tabela SET enviado = 1 WHERE enviado is null;
END
What this will do is run UPDATE until no record has been changed.
3 - Create a new table and copy the data
You can also create a new table (table v2) with the new structure you want to add (A column with default value for example) and copy the old contents of
table to the table v2 down to the last known id. The trick here is to add triggers in the table table to synchronize the information while the data is being copied. In the end, the process is similar to the first point, the table for table and name of table v2 for table. and will have your data updated and the new structure without any downtime.
4 - SQL Parallel Boost (http://sqlparallelboost.codeplex.com)
You can always take a look at this site.
I hope you’ve been helpful.
Note: NOLOCK is a hint, you are merely suggesting for the engine it does not use Locks but it can choose to scale the lock and often it does so when dealing with lots of data at once. As for your update, try doing it during a maintenance window, you have any idea how many records will be updated?
– jean
@Jean, about 2.5 million
– Andre Figueiredo
All records will be updated?! Well, I advise to really use a maintenance window, leave the bank in single mode, take advantage p/ make a backup, maybe a reindex and send see.
– jean
I created an index for the column to change, I went through a maintenance window and it was relatively fast: 1min30
– Andre Figueiredo
@Andréfigueiredo, but the column is only used as filtering? Or is there reading in any query of all columns of this table?
– Bruno Costa