Questions tagged [transactions]

A set of interrelated operations that must all succeed in order for any of them to succeed. Failure of any operation results in a rollback of all operations in the transaction.

In computer science, transaction processing is information processing that is divided into individual, indivisible operations, called transactions. Each transaction must succeed or fail as a complete unit; it cannot remain in an intermediate state.

Transaction processing is designed to maintain a system's Integrity (typically a database or some modern filesystems) in a known, consistent state, by ensuring that interdependent operations on the system are either all completed successfully or all canceled successfully.

Since most, though not necessarily all, transaction processing today is interactive the term is often treated as synonymous with online transaction processing

16096 questions
174
votes
14 answers

What is a database transaction?

Can someone provide a straightforward, yet not oversimplified explanation of a transaction as applied to computing?
Vlad Gudim
  • 23,397
  • 16
  • 69
  • 92
168
votes
3 answers

When to use SELECT ... FOR UPDATE?

Please help me understand the use-case behind SELECT ... FOR UPDATE. Question 1: Is the following a good example of when SELECT ... FOR UPDATE should be used? Given: rooms[id] tags[id, name] room_tags[room_id, tag_id] room_id and tag_id are…
Gili
  • 86,244
  • 97
  • 390
  • 689
163
votes
15 answers

Fixing "Lock wait timeout exceeded; try restarting transaction" for a 'stuck" Mysql table?

From a script I sent a query like this thousands of times to my local database: update some_table set some_column = some_value I forgot to add the where part, so the same column was set to the same a value for all the rows in the table and this was…
Tom
  • 7,515
  • 7
  • 38
  • 54
152
votes
5 answers

Transactions in .net

What are the best practices to do transactions in C# .Net 2.0. What are the classes that should be used? What are the pitfalls to look out for etc. All that commit and rollback stuff. I'm just starting a project where I might need to do some…
Malik Daud Ahmad Khokhar
  • 13,470
  • 24
  • 79
  • 81
152
votes
6 answers

How to use transactions with dapper.net?

I would like to run multiple insert statements on multiple tables. I am using dapper.net. I don't see any way to handle transactions with dapper.net. Please share your ideas on how to use transactions with dapper.net.
Amit
  • 25,106
  • 25
  • 75
  • 116
146
votes
9 answers

How to work around the lack of transactions in MongoDB?

I know there are similar questions here but they are either telling me to switch back to regular RDBMS systems if I need transactions or use atomic operations or two-phase commit. The second solution seems the best choice. The third I don't wish to…
NagyI
  • 5,907
  • 8
  • 55
  • 83
141
votes
10 answers

What happens if you don't commit a transaction to a database (say, SQL Server)?

Suppose I have a query: begin tran -- some other sql code And then I forget to commit or roll back. If another client tries to execute a query, what would happen?
Charbel
  • 14,187
  • 12
  • 44
  • 66
139
votes
7 answers

MySQL: Transactions vs Locking Tables

I'm a bit confused with transactions vs locking tables to ensure database integrity and make sure a SELECT and UPDATE remain in sync and no other connection interferes with it. I need to: SELECT * FROM table WHERE (...) LIMIT 1 if (condition…
Ryan
  • 17,511
  • 23
  • 63
  • 88
133
votes
2 answers

Best way to work with transactions in MS SQL Server Management Studio

Let's say I have an SQL statement that's syntactically and semantically correct so it executes. In Management Studio (or any other query tool) how can I test SQL statements, and if I notice that they broke something, rollback (in a separate query?)
Niels Bosma
  • 11,758
  • 29
  • 89
  • 148
133
votes
8 answers

Laravel: Using try...catch with DB::transaction()

We all use DB::transaction() for multiple insert queries. In doing so, should a try...catch be placed inside it or wrapping it? Is it even necessary to include a try...catch when a transaction will automatically fail if something goes wrong? Sample…
enchance
  • 29,075
  • 35
  • 87
  • 127
132
votes
3 answers

Correct use of flush() in JPA/Hibernate

I was gathering information about the flush() method, but I'm not quite clear when to use it and how to use it correctly. From what I read, my understanding is that the contents of the persistence context will be synchronized with the database, i.…
MicSim
  • 26,265
  • 16
  • 90
  • 133
131
votes
4 answers

Is there a way to list open transactions on SQL Server 2000 database?

Does anyone know of any way to list open transactions on SQL Server 2000 database? I am aware that I can query the view sys.dm_tran_session_transactions on SQL 2005 (and later) database versions, however this is not available on SQL 2000.
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
129
votes
4 answers

Why do I need Transaction in Hibernate for read-only operations?

Why do I need Transaction in Hibernate for read-only operations? Does the following transaction put a lock in the DB? Example code to fetch from DB: Transaction tx = HibernateUtil.getCurrentSession().beginTransaction(); // why begin…
user93796
  • 18,749
  • 31
  • 94
  • 150
128
votes
5 answers

Is it possible to roll back CREATE TABLE and ALTER TABLE statements in major SQL databases?

I am working on a program that issues DDL. I would like to know whether CREATE TABLE and similar DDL can be rolled back in Postgres MySQL SQLite et al Describe how each database handles transactions with DDL.
joeforker
  • 40,459
  • 37
  • 151
  • 246
128
votes
9 answers

Transaction marked as rollback only: How do I find the cause

I am having issues with committing a transaction within my @Transactional method: methodA() { methodB() } @Transactional methodB() { ... em.persist(); ... em.flush(); log("OK"); } When I call methodB() from methodA(), the…
Vojtěch
  • 11,312
  • 31
  • 103
  • 173