?
Solved

Why a single update, delete and insert operations are atomic, even without using Begin Transaction ?

Posted on 2004-09-22
3
Medium Priority
?
285 Views
Last Modified: 2012-06-27
Hi,

I have a doubt about the internal behavior of how SQL Server handle errors in update/delete/insert operations.

If say, I have an "Update" statement, that will update 10000 records and in the middle of the update, some error happens, like a check constraint violation, I review the table and non of the records where updated. That's very nice, right ? Even without adding a Begin Transaction / Update|Delete|Insert ... / Commit transaction, the operation is always atomic.
So the question is how does it do it ?

I have some guess. First, could it be starting an internal/hidden transaction  ? If so, is that transaction the same kind of transaction we use in our code or do they have their own special internal transaction to handle this ?
Or, if this is not a transaction at all, then what is it ?

Thanks in advance,



0
Comment
Question by:fischermx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12125090
Your guess is correct, and it's called an "implicit" transaction. It's the same kind of transaction as when you write BEGIN TRAN in T-SQL.
0
 
LVL 1

Author Comment

by:fischermx
ID: 12125265

Thanks for your answer,  jdlambert1.

However, let me clarify this for other readers. The term "Implicit Transaction" has slightly different meaning. It is when you never have to call "begin transaction", you just say commit or rollback. You can do some insertions, then some udpates and so on, and then, you just call commit and all of them are commited.
Each next transaction begins exactly where the prior ended, without having to begin it explicitly, that's why they're called implicit :)

I understand that what I'm seeing is a sort-of implicit transaction, since it looks like a transaction and behaves like a transaction and since I didn't started, then it is "implicit" as you say. But I wanted clarify the term.

So, my question was what happens inside a SINGLE update statement that handles hundreds of records and it fails in the middle of it. I guess I may find a deeper anwser in Kalen Delaney's SQL Server book, which is on the way from amazon, but I wanted to gather some opinions here in the meantime.

Regards,

0
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 1500 total points
ID: 12125396
It's the same meaning to my way of thinking: a transaction must be explicit or implicit, and if your code doesn't state the beginning of the transaction, that's implicit. All the major RDBMS's use transactions for all single statements by design, for the sake of data integrity, obviously. If you want independent behavior, you have to put each record (or group of records you want done as a unit) in separate statements.

Inside SQL Server is a great book, and I hope they get Kalen to update it again for 2005.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question