Friday, June 15, 2012

Resolving blocking issues in SQL Server


1. Use nolock table hint on the source table when it selects data for archiving
2. Add proper indexes to accelerate the select statement.
3. Remove referential constraints if possible. E.g removing the foreign key if the application is proved to not beak the integrity.
4. Split transaction into smaller transactions by using set rowcount command
Declare @numrows int
Set @numrows=1
While (@numrows>0)
Begin
                (Begin tran)
Set rowcount 500
Delete xxxxx
(Commit tran)
(Waitfor delay ’00:00:0x’)
End
Set rowcount 0
5. Guaranty the data integrity in application level
(6. Make the archiving happen more frequently. E.g. hourly instead of daily)

No comments: