Transactions in sql server must be Isolated. It means that if a transaction is running and somebody else comes along and there’re trying to work with data that previous transaction working with, they’re not allowed to touch that.
Sql server handle this problem using concurrency and locks.
Concurrency is the process of managing who has access to data.
The way that access to data is managed by locks.
Shared Lock Known as a read lock, This type of lock is obtained anytime when issue a select query. Shared lock can be shared with others who are trying to read that data.
Exclusive locks Whn ever going to modify data this lock is issued. We need to make sure nobody else working with that data, reading or trying to modify that. This lock prevents others from accessing that data.
Intent lock If someone doing operation and we want make sure that nobody drops that table or nobody drops the database. This is where Intent lock is issued.
One of the issue with locks is it is bit of overhead.
Locks can be maintained at a few levels
Make sure that do locks as little data as possible and for as short a period of time as possible
We generally works with multiple tables in one operation. May be we want to insert data to order header and order detail table in one operation. Then what happens if only part of the operation succeeds. Some statements can be failed.
So we are with lot of possible problems inside our database when it comes to data integrity . This is where we need transactions.
Transactions will allow us to control the entirety of an operation and ensure that everything’s going to succeed or everything is going to get rolled back should something fail.
Transaction must meet ACID.
ACID is comprised with four different components.
A -> Atomic
Entire operation must succeed or the entire operation must fail, and it must do so as a single unit
C -> Consistent
Once the operation is complete, database must be left in a consistent or in a valid state
I -> Isolated
Every transaction must also be isolated, simply meaning that somebody else’s operation at the same time that I’m working on my data, is not allowed to impact my operation.
D -> Durable
The database should be durable enough to hold all its latest updates even if the system fails or restarts
There are three main commands in managing transaction manually.
This will mark the start of the transaction
We are going to execute this once we know everything is works fine.
If some thing went wrong we are going to execute this one. We got some errors and we want to Rollback the transaction.
My One of Clients came with a new requirement. It is creating Mobile app for his business. Actually It was mobile CRM application. So in that moment I didn’t have any mobile application development experience.
But Actually I wanted to experience Mobile application development. So I experienced some technologies. After doing some researches I came up with Ionic framework.