Lesson – 40 : Transactions ના Concepts

કમ્પ્યુટર સાયન્સ અને ખાસ કરીને ડેટાબેસ મેનેજમેન્ટ સિસ્ટમ (DBMS) માં Transaction એક ખૂબ મહત્વપૂર્ણ વિચાર છે. જ્યારે કોઈ યુઝર અથવા એપ્લિકેશન ડેટાબેસ પર કામ કરે છે, ત્યારે ઘણી બધી operations સાથે મળી એક unit of work બનાવે છે, જેને Transaction કહેવામાં આવે છે.


🔍 Transaction શું છે?

ડેટાબેસમાં લાગતા એક કરતાં વધુ operations (INSERT, UPDATE, DELETE, SELECT) જેને એક સાથે complete કરવાનો હોય, તેને Transaction કહેવામાં આવે છે.

📌 ઉદાહરણ:
બેંકમાં એક ખાતાથી બીજા ખાતામાં પૈસા ટ્રાન્સફર કરવા માટે 2 operations થાય છે:

  1. એકાઉન્ટ A માંથી પૈસા deduct કરવું

  2. એકાઉન્ટ B માં પૈસા add કરવું

જો આ બેમાંથી એક પણ operation fail થાય, તો Transaction આખું rollback થાય છે.


✨ Features of Transaction (ACID Properties)

Transaction ને reliable બનાવવા માટે ACID properties ખૂબ મહત્વપૂર્ણ છે.

1️⃣ Atomicity
  • Atomic = “બધું અથવા કઈ નહીં”

  • Transaction નો દરેક ભાગ સફળ થવો જરૂરી છે.

  • કોઈ એક ભાગ fail થાય → આખું transaction rollback થાય.

2️⃣ Consistency
  • Transaction ડેટાબેસને valid state માં જ રાખે છે.

  • Data update થાય છતાં ડેટાબેસના rules અને constraints સાચા રહે.

3️⃣ Isolation
  • અનેક transactions સાથે સાથે ચાલે છતાં
    એકબીજાના ડેટામાં હસ્તક્ષેપ ન થાય.

  • Example: બે લોકો એક જ સમયે balance check કરે → results mix ન થાય.

4️⃣ Durability
  • Transaction once committed → data permanently saved

  • System failure, power off થવા છતાં data محفوظ રહે છે.


🛠 Transaction ના States

Transaction કુલ 5 states માંથી પસાર થાય છે:

1️⃣ Active State
  • Transaction ચાલુ છે અને operations થઈ રહ્યા છે.

2️⃣ Partially Committed
  • Last statement execute થઈ ગયું છે.

3️⃣ Committed
  • Transaction સફળતાપૂર્વક પૂર્ણ.

  • Data permanently save થાય છે.

4️⃣ Failed State
  • કોઈ error અથવા failure ને કારણે transaction અટકાઈ જાય.

5️⃣ Aborted
  • Transaction rollback થઈ જાય છે અને DB ને previous state માં લાવવામાં આવે છે.


📌 Why Transactions are Important?

✔ System failure થી data corrupt ન થાય
✔ Multiple users સાથે કામ કરતાં પણ ડેટા સાચું રહે
✔ Banking, e-commerce, railway booking જેવી critical systems ને protection આપે
✔ Data integrity અને accuracy વધે


Transaction DBMS નો backbone છે.
ડેટાને correct, consistent અને reliable રાખવા માટે ACID properties સાથે transaction એક secure process આપે છે. કોઈપણ આધુનિક ડેટાબેસ સિસ્ટમમાં Transaction વગર data handling અશક્ય છે.