Solved

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

Posted on 2004-09-22
3
278 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
  • 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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL 2014 always on 31 58
Row insertion failed. Array 5 46
Run an action on recently added records to a table 13 59
SQL Availablity Groups List 2 6
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

809 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