Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction Isolations level in SQL Server

I am trying to update table, which controlls application (application performs some select statements). I would like to update the table in transaction with isolation level set to read uncommited, so if application doesn't work as expected I can rollback transactions.

But following code doesn't work:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 
go

begin transaction 
go

update [DB].[dbo].[Table] 
set ID = ID - 281 
where ID > 2

When I open another query window, I cannot query this table... I thought, that with such transaction level I would be able to query the table without rolling back/commiting transaction.

like image 819
Michał Turczyn Avatar asked Dec 15 '17 09:12

Michał Turczyn


People also ask

What is transaction isolation level in SQL Server?

Transactions specify an isolation level that defines how one transaction is isolated from other transactions. Isolation is the separation of resource or data modifications made by different transactions. Isolation levels are described for which concurrency side effects are allowed, such as dirty reads or phantom reads.

What are transaction isolation level means?

Transaction isolation levels are a measure of the extent to which transaction isolation succeeds. In particular, transaction isolation levels are defined by the presence or absence of the following phenomena: Dirty Reads A dirty read occurs when a transaction reads data that has not yet been committed.

Which isolation level is best in SQL Server?

Serializable. This is the highest isolation level and prevents all possible types of concurrency phenomena in SQL Server, but on the other hand, the serializable level decreases performance and increases the likelihood of deadlocks.


1 Answers

Isolation level works in another way as you suppose.

You can only read uncommitted data, but others still cannot see what you done within transaction until you commit.

If you want to see uncommitted data from this transaction in your select you need to set

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 

to this select

like image 180
michal.jakubeczy Avatar answered Sep 24 '22 01:09

michal.jakubeczy