views:

633

answers:

2

I'm running an upgrade script against a database hosted in Microsoft SQL Server. It's taking a while. Some of the queries are not worth optimising any further, for various reasons.

I'm the only person using this database: Is there a way that I can tell SQL Server to not bother with transactions/locking?

For instance, on a DELETE ... WHERE, does SQL need to get exclusive locks on the rows it's about to delete? If so, can I tell it not to bother, since this is the only running query?

+1  A: 

See SQL Query Performance - Do you feel dirty? (Dirty Reads).

Edit: This is just speculation, but if you are the only connection to the SQL Server, you could get exclusive lock at the table level using WITH (TABLOCKX). You are sacrificing concurrency, but it could get faster.

eed3si9n
Useful, so I've upvoted, but the query I'm actually having problems with is a DELETE ... WHERE; I've expanded my question.
Roger Lipscombe
That's okay as the DELETE command allows you to use some table hints as well, so eed3si9n's WITH (TABLOCKX) will work.
xahtep
A: 

Turn off Autocommit (aka implicit transactions); you'll need to do a commit() at the end. The log file will grow correspondingly large, be sure you've got enough disk space. Is tempdb on the same disk?

ja
This database and tempdb are both on the same 1TB volume (2x500GB, striped).
Roger Lipscombe