SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Hệ quản trị cơ sở dữ liệu

Transaction
Dư Phương Hạnh
Bộ môn Hệ thống thông tin
Khoa CNTT, trường Đại học Công nghệ
Đại học Quốc gia Hanoi
hanhdp@vnu.edu.vn
Introducing Transactions
 We live in a transactional world and we perceive that things
such as money, files, and data move from one place to
another.
 We understand that data doesn't really move. It gets copied
from storage and the new copy is inserted into a new storage
location, and then the original copy is deleted from its initial
location.
 In a database, a transaction is simply a mechanism to
ensure and verify that data gets to its intended destination.
Just like a purchase or bank transaction, both parties must
be satisfied with the results.
2

Hệ quản trị CSDL @ BM HTTT
Transaction Types
 Explicit Transaction.
– The explicit transaction is defined by the presence of an
explicit BEGIN TRANSACTION statement followed by
one or more dependent data modification statements and
completed with an explicit COMMIT TRANSACTION
statement.
– Error checking is added prior to the COMMIT
TRANSACTION statement so that if an error occurred the
transaction can be reversed with a ROLLBACK
TRANSACTION statement.

3

Hệ quản trị CSDL @ BM HTTT
Transaction Types
 Implicit Transaction.
– The implicit transaction follows the behavior of some
other database products in that whenever a data
modification is executed it implicitly begins a
transaction.
– However, it does not complete the transaction and
release the modified data until an explicit COMMIT
TRANSACTION or ROLLBACK TRANSACTION
statement is issued.
– Implicit transactions are enabled on a connection
basis with the SET IMPLICIT_TRANSACTIONS ON
command.
4

Hệ quản trị CSDL @ BM HTTT
Transaction Types
 Auto-Commit Transaction.
– If a data modification statement is executed against
the database without an explicit or implicit transaction,
it is considered an auto-commit transaction.
– The modification contained in an auto-commit
transaction follows the same pattern as other
transactions

5

Hệ quản trị CSDL @ BM HTTT
The ACID Test
 Most of us have been burned enough by data
loss problems to realize that steps must be
taken to ensure that data gets from one
place to another. Although there are a number
of benefits, this is what transactions are all
about.
 A bona fide transaction must meet the following
criteria:

6

Hệ quản trị CSDL @ BM HTTT
The ACID Test
Atomic — All steps and operations that are part of a transaction are
treated as an atomic unit. Either all succeed or all fail together.
Consistent — The outcome of any transaction is always
predictable; all of the operations either fail or succeed. All
operations abide by consistency rules and checks to ensure
data integrity within the database.
Isolated — Any operations performed before, during, or after the
transaction will see related data in a consistent state, rather
than in a state of partial completion. Any user or operation that
queries data affected by a transaction will perceive that the
entire transaction was committed instantaneously.
Durable — If a transaction succeeds, data is written to disk and
does not revert to its previous state. Data can survive system
failure.

7

Hệ quản trị CSDL @ BM HTTT
Hệ quản trị cơ sở dữ liệu

MySQL Transaction
Dư Phương Hạnh
Bộ môn Hệ thống thông tin
Khoa CNTT, trường Đại học Công nghệ
Đại học Quốc gia Hanoi
hanhdp@vnu.edu.vn
Using MySQL Transaction
 To start a transaction you use the START TRANSACTION
statement
 To undo MySQL statements you use ROLLBACK statement.
Note that there are several SQL statements you cannot use
ROLLBACK such as:
– CREATE / ALTER / DROP DATABASE
– CREATE /ALTER / DROP / RENAME / TRUNCATE TABLE
– CREATE / DROP INDEX
– CREATE / DROP EVENT
– CREATE / DROP FUNCTION
– CREATE / DROP PROCEDURE
– …
9

Hệ quản trị CSDL @ BM HTTT
Using MySQL Transaction
 To write the changes into the database within a
transaction you use the COMMIT statement.
 It is important to note that MySQL automatically
commit the changes to the database by default. To
force MySQL not to commit changes automatically,
you need to use the following statement:
SET autocommit = 0;

10

Hệ quản trị CSDL @ BM HTTT
Examples
Using MySQL transaction to add new sale order into
our Classicmodels database and add the transaction
processing steps:
– Start a transaction using START TRANSACTION
– Get latest sale order number from orders table, and use
the next sale order number as the new sale order
number.
– Insert a new sale order into orders table for a given
customer
– Insert new sale order items into orderdetails table
– Commit changes using COMMIT statement
– Get data from both table orders and orderdetails tables to
confirm the changes
11

Hệ quản trị CSDL @ BM HTTT
MySQL Transaction

12

Hệ quản trị CSDL @ BM HTTT
MySQL Transaction with savepoint

13

Hệ quản trị CSDL @ BM HTTT
MySQL Transaction with
savepoint
SAVEPOINT identifier
ROLLBACK [WORK] TO [SAVEPOINT] identifier
RELEASE SAVEPOINT identifier

14

Hệ quản trị CSDL @ BM HTTT
Hệ quản trị cơ sở dữ liệu

Isolation level
Dư Phương Hạnh
Bộ môn Hệ thống thông tin
Khoa CNTT, trường Đại học Công nghệ
Đại học Quốc gia Hanoi
hanhdp@vnu.edu.vn
Introduce
 Isolation is a property that defines how/when the 
changes made by one operation become visible to 
other concurrent operations.
 Of the four ACID properties in a DBMS, the isolation 
property is the one most often relaxed.
 The isolation levels defined by the ANSI/ISO 
SQL standard are listed as follows:

16

Hệ quản trị CSDL @ BM HTTT
Read phenomena
 Dirty Read

17

Hệ quản trị CSDL @ BM HTTT
Read phenomena
 Nonrepeatable read

18

Hệ quản trị CSDL @ BM HTTT
Read phenomena
 Phantom Reads

19

Hệ quản trị CSDL @ BM HTTT
Isolation levels

20

Hệ quản trị CSDL @ BM HTTT

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (9)

6.1 query optimization overview
6.1 query optimization overview6.1 query optimization overview
6.1 query optimization overview
 
01 gioithieu
01 gioithieu01 gioithieu
01 gioithieu
 
2.1 view
2.1 view2.1 view
2.1 view
 
2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sql2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sql
 
9. partitioning
9. partitioning9. partitioning
9. partitioning
 
7. backup & restore data
7. backup & restore data7. backup & restore data
7. backup & restore data
 
8.replication
8.replication8.replication
8.replication
 
C3 2
C3 2C3 2
C3 2
 
2.3 quan ly truy cap
2.3 quan ly truy cap2.3 quan ly truy cap
2.3 quan ly truy cap
 

Ähnlich wie 4.2 transaction 2

Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing ConceptNishant Munjal
 
Transactionsmanagement
TransactionsmanagementTransactionsmanagement
TransactionsmanagementSanjeev Gupta
 
Chapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error RecoveryChapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error RecoveryKunal Anand
 
Transaction management
Transaction managementTransaction management
Transaction managementArchanaMani2
 
Lecture1414_20592_Lecture1419_Transactions.ppt (2).pdf
Lecture1414_20592_Lecture1419_Transactions.ppt (2).pdfLecture1414_20592_Lecture1419_Transactions.ppt (2).pdf
Lecture1414_20592_Lecture1419_Transactions.ppt (2).pdfbadboy624277
 
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...DrCViji
 
Transaction processing ppt
Transaction processing pptTransaction processing ppt
Transaction processing pptJaved Khan
 
Transaction Properties in database | ACID Properties
Transaction Properties in database | ACID PropertiesTransaction Properties in database | ACID Properties
Transaction Properties in database | ACID Propertiesnomanbarki
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processingJafar Nesargi
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingJafar Nesargi
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingJafar Nesargi
 

Ähnlich wie 4.2 transaction 2 (20)

DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing Concept
 
Transactionsmanagement
TransactionsmanagementTransactionsmanagement
Transactionsmanagement
 
Chapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error RecoveryChapter-10 Transaction Processing and Error Recovery
Chapter-10 Transaction Processing and Error Recovery
 
Sistem manajemen basis data 8
Sistem manajemen basis data   8Sistem manajemen basis data   8
Sistem manajemen basis data 8
 
Transaction management
Transaction managementTransaction management
Transaction management
 
Autonomous transaction
Autonomous transactionAutonomous transaction
Autonomous transaction
 
Transaction
TransactionTransaction
Transaction
 
Lecture1414_20592_Lecture1419_Transactions.ppt (2).pdf
Lecture1414_20592_Lecture1419_Transactions.ppt (2).pdfLecture1414_20592_Lecture1419_Transactions.ppt (2).pdf
Lecture1414_20592_Lecture1419_Transactions.ppt (2).pdf
 
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
 
CH09.ppt
CH09.pptCH09.ppt
CH09.ppt
 
Sql transacation
Sql transacationSql transacation
Sql transacation
 
Transaction processing ppt
Transaction processing pptTransaction processing ppt
Transaction processing ppt
 
Transactions
TransactionsTransactions
Transactions
 
Tps revision 2017
Tps revision 2017Tps revision 2017
Tps revision 2017
 
Transaction Properties in database | ACID Properties
Transaction Properties in database | ACID PropertiesTransaction Properties in database | ACID Properties
Transaction Properties in database | ACID Properties
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processing
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processing
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processing
 
Transation.....thanveeer
Transation.....thanveeerTransation.....thanveeer
Transation.....thanveeer
 

Mehr von Trần Thanh (11)

07 trigger view
07 trigger view07 trigger view
07 trigger view
 
4 trigger
4  trigger4  trigger
4 trigger
 
Chuan
ChuanChuan
Chuan
 
C4 1 tuan 14
C4 1 tuan 14C4 1 tuan 14
C4 1 tuan 14
 
C3 2 (tuan6,7)
C3 2 (tuan6,7)C3 2 (tuan6,7)
C3 2 (tuan6,7)
 
C3 1
C3 1C3 1
C3 1
 
C2 2
C2 2C2 2
C2 2
 
C2 1
C2 1C2 1
C2 1
 
C1
C1C1
C1
 
C4 1
C4 1C4 1
C4 1
 
VoIP with Opensips
VoIP with OpensipsVoIP with Opensips
VoIP with Opensips
 

Kürzlich hochgeladen

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

4.2 transaction 2

  • 1. Hệ quản trị cơ sở dữ liệu Transaction Dư Phương Hạnh Bộ môn Hệ thống thông tin Khoa CNTT, trường Đại học Công nghệ Đại học Quốc gia Hanoi hanhdp@vnu.edu.vn
  • 2. Introducing Transactions  We live in a transactional world and we perceive that things such as money, files, and data move from one place to another.  We understand that data doesn't really move. It gets copied from storage and the new copy is inserted into a new storage location, and then the original copy is deleted from its initial location.  In a database, a transaction is simply a mechanism to ensure and verify that data gets to its intended destination. Just like a purchase or bank transaction, both parties must be satisfied with the results. 2 Hệ quản trị CSDL @ BM HTTT
  • 3. Transaction Types  Explicit Transaction. – The explicit transaction is defined by the presence of an explicit BEGIN TRANSACTION statement followed by one or more dependent data modification statements and completed with an explicit COMMIT TRANSACTION statement. – Error checking is added prior to the COMMIT TRANSACTION statement so that if an error occurred the transaction can be reversed with a ROLLBACK TRANSACTION statement. 3 Hệ quản trị CSDL @ BM HTTT
  • 4. Transaction Types  Implicit Transaction. – The implicit transaction follows the behavior of some other database products in that whenever a data modification is executed it implicitly begins a transaction. – However, it does not complete the transaction and release the modified data until an explicit COMMIT TRANSACTION or ROLLBACK TRANSACTION statement is issued. – Implicit transactions are enabled on a connection basis with the SET IMPLICIT_TRANSACTIONS ON command. 4 Hệ quản trị CSDL @ BM HTTT
  • 5. Transaction Types  Auto-Commit Transaction. – If a data modification statement is executed against the database without an explicit or implicit transaction, it is considered an auto-commit transaction. – The modification contained in an auto-commit transaction follows the same pattern as other transactions 5 Hệ quản trị CSDL @ BM HTTT
  • 6. The ACID Test  Most of us have been burned enough by data loss problems to realize that steps must be taken to ensure that data gets from one place to another. Although there are a number of benefits, this is what transactions are all about.  A bona fide transaction must meet the following criteria: 6 Hệ quản trị CSDL @ BM HTTT
  • 7. The ACID Test Atomic — All steps and operations that are part of a transaction are treated as an atomic unit. Either all succeed or all fail together. Consistent — The outcome of any transaction is always predictable; all of the operations either fail or succeed. All operations abide by consistency rules and checks to ensure data integrity within the database. Isolated — Any operations performed before, during, or after the transaction will see related data in a consistent state, rather than in a state of partial completion. Any user or operation that queries data affected by a transaction will perceive that the entire transaction was committed instantaneously. Durable — If a transaction succeeds, data is written to disk and does not revert to its previous state. Data can survive system failure. 7 Hệ quản trị CSDL @ BM HTTT
  • 8. Hệ quản trị cơ sở dữ liệu MySQL Transaction Dư Phương Hạnh Bộ môn Hệ thống thông tin Khoa CNTT, trường Đại học Công nghệ Đại học Quốc gia Hanoi hanhdp@vnu.edu.vn
  • 9. Using MySQL Transaction  To start a transaction you use the START TRANSACTION statement  To undo MySQL statements you use ROLLBACK statement. Note that there are several SQL statements you cannot use ROLLBACK such as: – CREATE / ALTER / DROP DATABASE – CREATE /ALTER / DROP / RENAME / TRUNCATE TABLE – CREATE / DROP INDEX – CREATE / DROP EVENT – CREATE / DROP FUNCTION – CREATE / DROP PROCEDURE – … 9 Hệ quản trị CSDL @ BM HTTT
  • 10. Using MySQL Transaction  To write the changes into the database within a transaction you use the COMMIT statement.  It is important to note that MySQL automatically commit the changes to the database by default. To force MySQL not to commit changes automatically, you need to use the following statement: SET autocommit = 0; 10 Hệ quản trị CSDL @ BM HTTT
  • 11. Examples Using MySQL transaction to add new sale order into our Classicmodels database and add the transaction processing steps: – Start a transaction using START TRANSACTION – Get latest sale order number from orders table, and use the next sale order number as the new sale order number. – Insert a new sale order into orders table for a given customer – Insert new sale order items into orderdetails table – Commit changes using COMMIT statement – Get data from both table orders and orderdetails tables to confirm the changes 11 Hệ quản trị CSDL @ BM HTTT
  • 12. MySQL Transaction 12 Hệ quản trị CSDL @ BM HTTT
  • 13. MySQL Transaction with savepoint 13 Hệ quản trị CSDL @ BM HTTT
  • 14. MySQL Transaction with savepoint SAVEPOINT identifier ROLLBACK [WORK] TO [SAVEPOINT] identifier RELEASE SAVEPOINT identifier 14 Hệ quản trị CSDL @ BM HTTT
  • 15. Hệ quản trị cơ sở dữ liệu Isolation level Dư Phương Hạnh Bộ môn Hệ thống thông tin Khoa CNTT, trường Đại học Công nghệ Đại học Quốc gia Hanoi hanhdp@vnu.edu.vn
  • 17. Read phenomena  Dirty Read 17 Hệ quản trị CSDL @ BM HTTT
  • 18. Read phenomena  Nonrepeatable read 18 Hệ quản trị CSDL @ BM HTTT
  • 19. Read phenomena  Phantom Reads 19 Hệ quản trị CSDL @ BM HTTT
  • 20. Isolation levels 20 Hệ quản trị CSDL @ BM HTTT