Normalization, Transactions Flashcards
Unnormalized form
probably no relationships, just one large table (pro: no joins, easy to restructure, good for NoSQL; con: data duplication, empty attributes, non-atomic attributes)
First normal form
each attribute must contain atomic values
Second normal form
must be in 1NF and all non-key columns must describe the primary key
Third normal form
must be in 2NF, cannot have attributes that provide facts about non-key attributes (“about the key, the whole key, and nothing but the key”)
Transaction
sequence of statements/queries executed as a single unit (all-or-nothing)
ACID properties
guarantee transactions maintain the integrity of the database, Atomicity, Consistency, Isolation, Durability
Atomicity
require that each transaction be all-or-nothing, they are never “in progress”
Consistency
a transaction must change the database from one valid state to another valid state, must maintain constraints
Isolation
defines WHEN changes to the database are visible to others
Durability
guarantees that successful transactions are committed to the database
Isolation levels
Serializable, repeatable reads, read committed, read uncommitted
Lock
mechanism for securing data for a transaction
2PL
two-phase locking protocol, use a read lock and a write lock
Expanding phase
first part of 2PL, locks are acquired before the transaction begins
Shrinking phase
last part of 2PL, locks are released after the transaction commits/rolls back
Serializable
strictest level of isolation, can only execute one transaction on a given unit of data at a time
Dirty read
when a transaction retrieves a row that has been updated by another transaction that is not yet committed
Non-repeatable read
when a transaction retrieves a row twice and that row is updated by another transaction that is committed in between
Phantom read
when a transaction retrieves a set of rows twice and new rows are inserted into or removed from that set by another transaction that is committed in between
Repeatable reads
2nd strictest, does not maintain range locks and results in phantom reads
Read committed
3rd strictest, does not maintain range locks and releases read locks immediately after use (data can change after it is read). Results in non-repeatable reads
Read uncommitted
least strict, allows users to read data that is not yet committed (dirty reads)