Given the following scenario:
A select statement is executed from Sql Server Management Studio (2005, 2008) to retrieve a large resultset. This is not done by choosing ‘Edit top 200 rows’ from the context menu.
Our DBA says that it’s possible this can lock the table being queried. Unlocking occurs when the query results are closed.
I can’t find any documentation that confirms this is true.
So, fact or fiction?
Edit:
Selected Aaron’s answer, and thumbs up to Yuri and Lloyd for helpful answers.
Regards,
Michel
A SELECT is run once, and the shared locks (not exclusive locks!) are released once the data has completed being read. This may coincide precisely with the last row being displayed on the client, but it may occur a few milliseconds before. The fact that the results are open on the client is not known by SQL Server (unless we are talking about “Open Table” / “Edit Top 200 Rows”). I don’t think it’s possible with a single SELECT statement to lock the table in the way you describe – other readers and writers should be able to operate on the table just fine, though there may be some contention (not exclusive locking) while your SELECT is running.
A way you could simulate this, however, is to do some combination of…
…and then go to lunch.