--> Skip to main content

MYSQL PART-15 IN HINDI

Views
MYSQL  PART-15 IN HINDI
MYSQL  PART-15 IN HINDI
MYSQL  PART-15 IN HINDI

MySQL Transactions

Introduction to MySQL transactions 
एक transaction कुछ DML statements का group होता है। इस group के सभी statements एक साथ एक statement की तरह execute किये जाते है। इसका मतलब ये हुआ की यदि इन statements में से एक भी statement का execution fail हो जाये तो पूरा transaction ही fail हो जाता है। 

एक transaction केवल तब ही successfully execute होता है जब सभी statements successfully execute होते है। 

इसका सबसे अच्छा उदाहरण banking system होता है। मान लीजिये आप अपने किसी एक account से ₹1000 दूसरे किसी account में transfer कर रहे है। इस task को complete करने के कई steps हो सकते है जैसे की -
सबसे पहले ये check किया जायेगा की आपके account में ₹1000 है या नहीं है।


 इसके बाद एक account से ₹1000 निकाले जायेंगे। (Main balance - ₹1000)इसके बाद दूसरे account में ₹1000 जमा किये जायेंगे। (Main balance + ₹1000)इन सभी steps को आप एक MySQL transaction के वो statements मान सकते है जो एक साथ execute होंगे। यदि इन steps में से एक भी step successful नहीं रहता है तो पूरा transaction ही fail हो जाता है। 


किसी भी transaction के fail होने से पहले जो भी changes database में किये गए थे उन्हें rollback (database पुरानी situation में आ जाता है।) कर लिया जाता है। इससे database की integrity कायम रहती है। मान लीजिये आपने second step complete कर लिया है और third step को complete करते समय कोई technical error आ गयी तो transaction fail हो जायेगा। ऐसी situation में यदि first और second steps rollback नहीं किये जायेंगे तो database accurate नहीं माना जायेगा।      

Transactions के बारे में और अधिक जानने से पहले मै आपको ये बताना चाहता हूँ की transactions केवल उन्हीं storage engines के साथ काम करते है जो transactions को support करते है जैसे की InnoDB storage engine आदि। इन्हें transnational storage engines कहा जाता है।  
Comment Policy: Please write your comments that match the topic of this page's posts. Comments that contain links will not be displayed until they are approved.
Leave a Comment
Close comments