2 years ago

#64575

test-img

Gani P

Read committed data within a transaction in sql server

I want to read data without dirty reads in the middle of a transaction. Is that possible?

CREATE TABLE [dbo].[Tbl](
    [Id] [int] NOT NULL,
    [Detail] [varchar](50) NULL)

insert into Tbl values(1,'abc')
select * from Tbl where id = 1

begin tran
update Tbl set Detail = 'def' where id = 1

select * from Tbl

-- here I need "abc" as a return because the transaction is not yet committed.
-- It is in the middle of it. But it is returning me "def" only.
select * from Tbl (readcommitted)

rollback tran

select * from Tbl where id = 1
drop table Tbl

Assigning it to a variable before update is not what I'm looking for, because I will run the scripts in a for loop inside a single transaction.

eg:

transaction.begin
foreach file
sqlcmd.executenonquery(<my script goes here>)
transaction.end

.net

sql-server

ado.net

0 Answers

Your Answer

Accepted video resources