SQL 3 Flashcards
Transactions
Units of work done on a database that may include many operations (Database Manipulation Language, DML)
ACID
Atomicity
Consistency
Isolation
Durability
Atomicity
Smallest logical unit that can be run.
All or nothing.
All operations execute successfully or rollback.
If we have bad atomicity, we can lose referential integrity.
Consistency
Database is in a valid state according to existing structure and constraints after a commit.
Isolation
Concurrent transactions do not affect each other.
One transaction must complete before another may execute, to sharing resources.
The system state during concurrent transactions is the same as if transactions were sequential.
Durability
If you shoot it, you have a backup.
Even in catastrophic failure of a database, the transaction will complete.
All commits are final and cannot be rolled back even in system failure.
Oracle 10g
Transaction Phenomenon
Issues that occur with concurrent transactions.
TYPES
Dirty Read
Non-Repeatable Read
Phantom Read
Dirty Read
returns something from a column/table that has not been committed.
Example
Session 1 - Begin transaction and modifies data
Session 2 - Begins with Session 1’s uncommitted data
If Session 1 rolls back, Session 2’s data is now invalid.
Non-Repeatable Read
Row is edited after being viewed · Session 1 begins TX, returns a row of data · Session 2 update same row and commit · Session 1 TX is still in progress, can’t same row · Example Session 1 Begin TX SELECT Name for VG WHERE Genre=RPG § Zelda and Dark Souls Session 2 Begin TX Update ID2 to Adventure Commit
Phantom Read
Query that does not return the same result when read again in a transaction. Example Session 1 Begins a TX Executes Query Session 2 Inserts data matching that Query Session 1 Re-runs that Query and finds something that wasn’t there before. Phantom Data has occurred.
Isolation Levels
Think of these as locks on our read-write permissions.
These are set up per database.
Need concurrent access to the database. Always assume thousands of people will be accessing your database concurrently.
Read-uncommitted
Read-committed (Oracle Default)
Repeatable Read
Serializable
Read Uncommitted
Terrible. No locks. ALLOWS FOR DIRTY READ Non-Repeatable Read Phantom Read
Read-committed (Oracle Default)
Oracle default.
It allows only committed data to be read, eliminating the dirty read problem.
Write Lock
ALLOWS FOR
Non-Repeatable Read
Phantom Read
DOES NOT ALLOW
Dirty read
Repeatable Read
Write and Read Lock
ALLOWS FOR
Phantom Read
DOES NOT ALLOW
Dirty read
Non-Repeatable Read
Serializable
Most secure, but very slow.
Banks often use these, since their information needs to remain highly secure.
Read, Write and Range Lock
DOES NOT ALLOW
Dirty read
Non-Repeatable Read
Phantom Read