كل المقررات

الرئيسية / مقرر قاعدة البيانات / الفصل 9 الجزء 2

الفصل 9 (الجزء 2): Introduction to Transactions

Schedules and serializability

على طول: لما transactions كتير تشتغل مع بعض، الترتيب بيفرق. وإيه الـ serial وـ serializable schedule.

فيديو المحاضرة

فيديو المحاضرة

بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.

رسوم متحركة

تداخل الـ transactions

أمثلة SQL

أمثلة قصيرة وبسيطة

الكود قصير والنتيجة اتجرّبت فعلاً. عدّل في المحرر واضغط شغّل.

المثال ١: Serial: T1 وبعدين T2

Sample output (press Run to produce your own):
final_value
-----------
90         
(1 row)

المثال ٢: Lost update (مداخلة بالقيم)

Sample output (press Run to produce your own):
final_value
-----------
80         
(1 row)

المثال ٣: Dirty read (مداخلة بالقيم)

Sample output (press Run to produce your own):
t2_reads
--------
500     
(1 row)
real_value
----------
100       
(1 row)

افتح الموضوع المقابل في صفحة LiU TDDD12

اختبار قصير

اختبر فهمك

1. A serial schedule runs:

2. A lost update is:

3. A schedule is serializable if its result equals:

4. Two operations conflict if they touch the same item and:

5. A cycle in the precedence graph means:

تمارين برمجة

جرّب بإيدك

التمرين 1

نفّذ الـ serial T2 ثم T1: اطرح 20 وبعدين أضف 10 على 100. قارن مع المثال ١.

Run the serial order T2 then T1: subtract 20 then add 10 on 100. Compare with example 1.

(output appears here)

التمرين 2

حاكي lost update بحيث T1 تضيف 50 وT2 تضيف 30 على 200 وكلاهم قرا 200. إيه الناتج وإيه كان المفروض؟

Simulate a lost update: T1 adds 50 and T2 adds 30 to 200, both read 200. What is the result and what should it be?

(output appears here)

مشروع صغير في آخر المحاضرة

حاكي مشاكل التداخل على رصيد

الداتا: One account with balance 1000. Written for this course (our own data, free to reuse).

License / source: Our own sample data; SQLite is in the public domain. Dataset page

الخطوات

  1. الجدول acc فيه رصيد 1000.
  2. T1 بتسحب 100 وT2 بتودّع 200، والاتنين قروا 1000. حاكي lost update. المتوقع: 1200 (غلط).
  3. أعد الرصيد 1000 ونفّذ serial صح. المتوقع: 1100.
  4. اعرض الرصيدين جنب بعض.
Expected output (press Run to produce your own):
lost_update
-----------
1200       
(1 row)
serial
------
1100  
(1 row)

مشروع نهاية الفصل

ملف المشروع العملي للفصل 9

ملف PDF فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.

افتح ملف المشروع (PDF)

Credits: the topic order follows the lecture list of the course TDDD12 Database Technology at Linköping University (https://www.ida.liu.se/~TDDD12/fo/), whose reading guide is based on the textbook Fundamentals of Database Systems by Elmasri and Navathe. We found no reuse licence on that page, so we link to it and copy nothing from it: the explanations, diagrams, data and code in this lecture are our own. Reference: Elmasri and Navathe, Fundamentals of Database Systems, the chapters on transaction processing.