Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Specifying Isolation Level for Transaction | Section
SQL-Optimierung und Abfragefunktionen
Abschnitt 1. Kapitel 7
single

single

bookChallenge: Specifying Isolation Level for Transaction

Swipe um das Menü anzuzeigen

In this challenge, you will practice setting the isolation level for a transaction to ensure data consistency during a funds transfer. Using the bank_accounts and transfers tables, your goal is to write a SQL transaction that sets the isolation level to Repeatable Read before performing a transfer of funds between two accounts. The transaction should ensure that no phantom reads can occur, meaning that the set of rows read at the beginning of the transaction remains unchanged for the duration of the transaction—even if other concurrent transactions attempt to insert or modify relevant data.

You will use the following steps: set the isolation level, begin the transaction, select the current balances, update the balances, insert a record into the transfers table, and commit the transaction. The transaction must be robust against phantom reads, as required by the Repeatable Read isolation level.

Aufgabe

Swipe to start coding

Write a SQL transaction that transfers 1000.00 from account 1 to account 2, ensuring the transaction uses the Repeatable Read isolation level to prevent phantom reads.

  • Set the isolation level to Repeatable Read before starting the transaction.
  • Deduct 1000.00 from the balance of account 1.
  • Add 1000.00 to the balance of account 2.
  • Insert a record of the transfer into the transfers table, specifying the correct from_account, to_account, and amount.
  • Ensure all changes are made within a single transaction.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 7
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

some-alt