Let create a database and a table for testing isolation levels.
READ UNCOMMITTED
READ UNCOMMITTED isolation level allows a transaction to read data from
the data or index page, regardless of whether a transaction is committed.
the data or index page, regardless of whether a transaction is committed.
Firstly make a connection then start a transaction but should not commit it.
First Connection
And we should make a new connection and we set read uncommited isolation level.
Then execute select query.
Second Connection
If you look at the query result set, you can see the uncommitted data.
But if you execute rollback command in the first connection screen then you
execute second connection select script again, it brings old record again.
execute second connection select script again, it brings old record again.
The result set is:
old record
READ COMMITTED
READ COMMITTED is Sql Server’s default isolation level.
If a transaction has made a change but it has no commit, read committed
isolation level doesn't allow another transaction for reading.
If a transaction has made a change but it has no commit, read committed
isolation level doesn't allow another transaction for reading.
Let's do the same plan again. But we must make one change.
Firstly, open a connection then execute below script:
First Connection
And then we should execute second script but we must change isolation level to
read committed like below:
read committed like below:
Second Connection
If you notice, there are no results, no messages.
Because second process is being blocked by first process.
Because second process is being blocked by first process.
If I execute sp_who2 procedure, I can see the blocking.
For this example first process’s session id is 66, second’s session id is 65.
For this example first process’s session id is 66, second’s session id is 65.
If you want to finish up the blocking, you can execute rollback or commit command in the
first connection.
first connection.
Different Scenario
Let’s execute below scripts step-by-step.
Open first connection:
Open second connection (it is an update script)
Then we should turn back to first connection. Firstly we should execute third step.
And we will see that the record was changed.
And we will see that the record was changed.
The isolation level READ COMMITTED guarantees only that a transaction will not
read uncommitted data.
read uncommitted data.