Core component of SQL Server for storing, processing, and securing data
DO NOT DO THIS! ABSOLUTELY NOT!
Most likely this will result in the SELECT statements occasionally returning incorrect results, which users may or may not notice. If they notice, you will get bug reports you cannot reproduce. If they do not notice, they may make incorrect business decisions based on the incorrect data.
When you use READ UNCOMMITTED, several bad things can happen:
- You read uncommitted and inconsistent data.
- You fail to read existing data, because it was moved while tables were being scanned.
- You may read the same data twice, again due to data movement.
- The query may fail with error 601.
The correct solution to this type of blocking problem is to apply some form of snapshot solution. There are two ways to go.
- ALTER DATABASE db SET READ_COMMITTED_SNAPSHOT ON. With this setting, all reads will be from a snapshot which reflects how the database looked like when the query started. This setting is on by default in Azure SQL Database and is generally recommended. However, you will be reading stale data, and in some situations this can cause incorrect results, for instance with validation. This can be overridden with the READCOMMITEDLOCK hint, but you need to change the code.
- ALTER DATABASE db SET ALLOW_SNAPSHOT_ISOLATION ON. With this setting, code that want to use the snapshot needs to opt in with SET TRANSACTION ISOLATION LEVEL SNAPSHOT. With this setting, queries sees the database as when then transaction started.
Both these settings activates the version store, which lives in tempdb (unless you have activated accelerated database recovery), which means that tempdb will need more space, and overall the load on tempdb will increase. It also adds an overhead to UPDATE and DELETE operations (not so much to INSERT). This overhead is usually acceptable.
READ UNCOMMITTED a.k.a. NOLOCK can be useful for diagnostic queries, but it rarely has any place in application code.