Database transaction and locking

I am trying to learn using databases correctly by myself and now I realised, that although I have used these concepts before, I don't really know what's the difference between them:

What is a transaction? What is a lock?

As far as I know, when using a transaction, all instructions are executed as one, so another user can not interfere. So why would I use a lock in this case? When should I use locking and when transactions?

I am using MySQL, if it matters...

Answers


Transactions are used when you are executing queries and wish to have a mechanism to reverse the resulting modifications if there is a possibility of error during their execution.

Locking in mysql is used to gain exclusive mode to certain table and perform much faster insert/delete queries, most often for bulk data upload into a heavy usage database.


The transaction is a unit, it is necessary for guaranteed atomicity, or all of these steps are done or not done any. It is necessary to do so because normally the operations on the database require you to perform various operations of reading, writing, and others, and only successful execution of all ensures compliance to the target.

To better understand read about ACID (atomicity, consistency, isolation, durability), these are the characteristics that guarantee that a transaction is processed reliably.


Transaction is, we can say the execution of DML statements. When we use the DML statements for inserting, updating,selecting,and deleting data from database then transaction to be performed. In the all over transactions controlled by transactions management.


Need Your Help

Join two unrelated SELECT queries

mysql sql

I need to join two unrelated SQL SELECTS into one table.

Running phantomjs from a Ruby on Rails application

ruby-on-rails ruby ruby-on-rails-3 command-line phantomjs

I'm interested in using Phantomjs and I'd like to run it from my Ruby on Rails application. However, this is a command line tool (i.e. I'd need to run something like phantomjs rasterize.js

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.