473,474 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Retrieving updates made within a transaction?

Hi All,

This seems like a tricky question to me. I have a Stored Procedure
that encapsulates a number of updates to various tables within a
transaction.

However, at a later part of the transaction I need to be able to
select records changed by an update statement made earlier within the
same stored proc (and within the same transaction) and need for that
select to reflect the changed values.

My understanding, however, is that the records aren't actually changed
by the update statement until the transaction is committed, and
therefore my later select statement won't return the expected records
because the update is being held until the transaction is committed.

Is this accurate? And, if so, is there a reasonable workaround that
still leaves me able to rollback the entire transaction if I strike a
problem somewhere along the way?

So, a pseudo code example would be:
BEGIN TRANSACTION

UPDATE mytable SET myid = @yourid WHERE myid = @id

SELECT * FROM mytable where myid = @id

COMMIT TRANSACTION

In this above example, would the select statement return the records
that have a myid value of @id as before the update as after the
update?

Many, many thanks in advance!

Much warmth,

Murray
Jul 20 '05 #1
2 2385
On Thu, 01 Apr 2004 16:26:01 GMT, M Wells wrote:

(snip)
My understanding, however, is that the records aren't actually changed
by the update statement until the transaction is committed, and
therefore my later select statement won't return the expected records
because the update is being held until the transaction is committed.

Is this accurate?
No. The updates are made. If you rollback the transaction later, the
changes will be undone; the log file is used for this. During the
transaction, you'll get to see the changed data.

Other users (or even you yourself on another connection!) won't see
the changed data until the transaction is committed (*). They won't
see the old data either. The affected rows are locked as soon as they
are hit by an update and this lock will remain until the transaction
is either committed or rolled back.

(*) Exception - you can set a transaction's isolation level to "Read
uncommitted" (aka dirty read). This will cause select statements to
defy any locks and just read the "dirty" data - "dirty", since the
transaction may still be rolled back in which case the reading
transaction has read data that never really existed.
So, a pseudo code example would be:
BEGIN TRANSACTION

UPDATE mytable SET myid = @yourid WHERE myid = @id

SELECT * FROM mytable where myid = @id

COMMIT TRANSACTION

In this above example, would the select statement return the records
that have a myid value of @id as before the update as after the
update?


It won't return any rows at all, since the update has just changed to
myid value from @id to @yourid.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
On Thu, 01 Apr 2004 21:28:22 +0200, Hugo Kornelis
<hugo@pe_NO_rFact.in_SPAM_fo> wrote:


BEGIN TRANSACTION

UPDATE mytable SET myid = @yourid WHERE myid = @id

SELECT * FROM mytable where myid = @id

COMMIT TRANSACTION

In this above example, would the select statement return the records
that have a myid value of @id as before the update as after the
update?


It won't return any rows at all, since the update has just changed to
myid value from @id to @yourid.


Hi Hugo,

Thanks for your help! And, laugh, just shows I shouldn't write pseudo
sql before my first cup of coffee.

Thanks again!

Much warmth,

Murray
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BFord | last post by:
Using SQL2000, is there another way of optimizing the original query below. TIA, Bob Update Transaction set field1 = (select (sum(tax)-sum(credit))/sum(credit) from tblOrder where tblOrder.id...
0
by: Manoj Sharma | last post by:
I am performance testing some batch processing engines. These are written in ..NET and SQL Server and are typically concerned with generating XML files out of data retrieved from the database. I...
4
by: sebmil | last post by:
Hello, I have a table with two columns, created with : CREATE TABLE test ( id serial primary key, name text ) ; To populate the table i use : INSERT INTO test(name) values('test1'); so the...
6
by: Dave Hopper | last post by:
Hi I am using the following SQL to retrieve a value in a list box using a unique ID held in the list box call cntID. The list box is used on an order form to list appointments that have been...
5
by: Jill Graham | last post by:
Hi, What is the best way to resolve following problem in a multi-user environment ? I have a table called TOTAL_SALES. The table has 2 columns : "CarId" and "TotalSales" I need to access a...
2
by: Leon | last post by:
How can I code a stored procedure "within my codebehind page" that execute two or more stored procedures within a transaction? if so how would I pass values to each parameter? i.e. Begin Tran...
17
by: Rico | last post by:
Hello, I am in the midst of converting an Access back end to SQL Server Express. The front end program (converted to Access 2003) uses DAO throughout. In Access, when I use recordset.AddNew I...
8
by: Dave | last post by:
I have a form with a label that should show an invoice number. The invoice number should be generated by sql Server using an autoincremented technique. However, after reading several articles, it...
1
by: myemail.an | last post by:
Hi all, I have a table with this structure: Customer ID | Transaction date | Transaction type 1 | 1/2/2008 | F 1 | 1/4/2007 | M...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.