أهداف الدرس
- أن تجعل عدة تعديلات تنجح معاً أو تفشل معاً.
نقل طالب من شعبة إلى أخرى تعديلان: حذف من الأولى وإضافة إلى الثانية. لو نجح الأول وفشل الثاني لضاع الطالب.
SQL
BEGIN;
DELETE FROM enrolments WHERE student_id = 42 AND section_id = 1;
INSERT INTO enrolments (student_id, section_id) VALUES (42, 2);
COMMIT; -- or ROLLBACK; to undo both| الخاصية | معناها |
|---|---|
| الذرّية | كل شيء أو لا شيء |
| الاتساق | القواعد تبقى صحيحة |
| العزل | المعاملات لا تتداخل |
| الديمومة | ما حُفظ لا يضيع |
تمرين
ماذا يحدث إن انقطع الاتصال قبل COMMIT؟
الإجابة
تُلغى التعديلات كلها، وتبقى البيانات كما كانت.
Lesson goals
- Make several changes succeed together or fail together.
Moving a student between sections is two changes: remove from one, add to the other. If the first works and the second fails, the student is lost.
SQL
BEGIN;
DELETE FROM enrolments WHERE student_id = 42 AND section_id = 1;
INSERT INTO enrolments (student_id, section_id) VALUES (42, 2);
COMMIT; -- or ROLLBACK; to undo both| Property | Meaning |
|---|---|
| Atomicity | All or nothing |
| Consistency | The rules stay true |
| Isolation | Transactions do not interfere |
| Durability | What is committed stays |
Exercise
What happens if the connection drops before COMMIT?
Answer
Every change is undone, and the data stays as it was.
التعليقات / Comments
لا تعليقات بعد. كن أول من يسأل. / No comments yet. Be the first to ask.