Should That Be One Update Statement or Multiple?


Let’s say we have a couple of update statements we need to run every 15 minutes in the Stack Overflow database, and we’ve built indexes to support them:

EXEC DropIndexes @TableName = N’Users’; CREATE INDEX LastAccessDate ON dbo.Users(LastAccessDate); CREATE INDEX AccountId ON dbo.Users(AccountId); GO BEGIN TRAN /* Give reputation points if folks did something in the last 15 minutes: */ UPDATE dbo.Users SET Reputation = Reputation + 100 WHERE LastAccessDate >= DATEADD(MINUTE, -15, GETDATE()); /* If we’re having account sync problems (AccountId = 0), reset their name/location: */ UPDATE dbo.Users SET DisplayName = N’Unknown’, Location = NULL WHERE AccountId =