Lecture 6 Flashcards
CASE example
SELECT *
CASE
.WHEN condition THEN text
.WHEN condition THEN text
.ELSE text
END
AS QuantityText
from OrderDetails;
CASE can also be used to…
Update
Transactions
- Make state transitions independent from atomic operations.
Ending Transitions
- You commit or rollback the transaction
- The server shuts down, this rolls back the transaction when the server is restarted.
- You use a schema statement, your transition is committed and a new one started.
- You use another start transaction, your transition is committed and a new one started.
- A deadlock is detected.
Transactions and ACID - A
Atomicity
- Transactions are often composed of multiple statements.
- Each transaction is treated as a single unit, which either succeeds completely, or fails completely.
Transactions and ACID - C
Consistency
- A transaction can only bring the database from one valid state to another valid state.
(FK, Unique Constraints, Cascades, Triggers)
Transactions and ACID - I
Isolation
- Concurrent transactions should not interfere with each other.
- Avoid dirty read/write
- Avoid non repeatable read
- Avoid phantom read
Race condition (definition)
- Undesirable situation that occurs when a device or system attempts to perform two operations at the same time, but operations must be done in a proper sequence.
Multi-user transactions - Locks intro
We use locks to prevent access to data undergoing transactions.
- Write/ Read lock
Locking can also be:
- Table, page or row locks
OLTP
Online Transaction Processing
- High volume of transactions
- Fast processing
- Normalised data
- Many tables
OLAP
Online Analytical Processing
- High volume of data
- Slow queries
- Denormalised data
- Fewer tables
Database files
A database file contains descriptions of how input data is to be presented to a program from internal storage and how output data is to be presented to internal storage from a program.
Pages
- Every page contains a header of metadata about the pages contents.
Slotted ot log structured pages
NSM
N-ARY Storage Model
- DBMS stores all attributes for a single row contiguously in a page.
NSM Advantages and Disadvantages
A:
- Fast inserts, updates, and deletes.
- Good for queries that need the entire tuple.
Drawbacks:
- Not good for scanning large portions of the table and/or a subset of the attributes.