Session 7 - Transactions, Indexes, Optimize Queries, dynamic views, cursors Flashcards
What is the term for when a database searches an indexed value?
SEEK
What is the term for when a database searches for a non indexed value?
SCAN
What are the characteristics of a transaction?
- Atomicity - Single unit of work
- Consistency - Everything has to be done
- Isolation - Each transaction must be isolated (database locking)
- Durability - Once a transaction is done, it is committed - Permanent
What is it called when you write a statement that starts and ends without the user telling the computer that it’s a transaction?
Implicit Transaction.
What is it called when you tell the computer when you start and end a transaction?
Explicit Transaction.
What are the two ways to end a transaction?
COMMIT TRANSACTION
ROLLBACK TRANSACTION
How do you assign in the log the name of a transaction?
BEGIN TRANSACTION tranName WITH MARK
ROLLBACK TRANSACTION tranName
What is the net effect if you rollback a transaction that has nested transactions?
Any transactions that were committed within the parent transaction will be rolled back as well.
What happens if you rollback a child nested transaction and try to commit the parent transaction?
It will fail because a rollback transaction rolls back EVERYTHING.
How do you find out the nested level of a transaction?
SELECT @@TRANCOUNT
What are the scope and types of locks?
- Intent Shared (IS)
- Shared (S)
- Update (U)
- Intent Exclusive (IE)
- Shared with intent exclusive (SIX)
- Exclusive (X)
What are the elements of shared locks? (SELECT query)
- Allows concurrent transactions to read (SELECT)
- No other transactions can modify the data
- Released as soon as the read operation is completed
What are the elements of Update Locks?
- Used to prevent deadlock
- Transactions reading data - Shared Lock
- To update data, must convert to exclusive
- Cannot convert to Exclusive if there is a Shared Lock.
- Solution - Use Update Lock; then convert to Exclusive Lock.
What are the elements of Exclusive Locks?
- Prevents access by concurrent transactions
2. Used by INSERT, UPDATE, DELETE
What are the elements of Intent Locks?
- Signal intent to place locks at a lower level.
- Prevent other transactions from modifying higher level resources
- Detecting lock conflicts
What are the scopes where locks are used?
Rows, Pages and Tables
What is the order that locks go?
Shared -> Update -> Exclusive
How can you delay a transaction from running for a specified amount of time (EX. 10 Seconds)?
WAITFOR DELAY ‘00:00:10’
How can you specify when to run a transaction at a specific time (EX. 10am)?
WAITFOR TIME ‘10:00:00’
What are the problems with no concurrency control (ie: no locks, etc)
- Lost Updates
- Uncommitted dependency (Dirty Read)
- Inconsistent analysis (nonrepeatable read)
- Phantom Reads
- Missing and double reads caused by row updates
- Missing one or more rows that were not the target of update
What are the transaction isolation levels?
- Read Committed (Default Isolation Level)
- Read Uncommitted
- Repeatable Read
- Snapshot
- Serializable
What are the transaction isolation level effects for:
Read Uncommitted
Dirty Read - YES
NonRepeatable Read - YES
Phantom - YES
What are the transaction isolation level effects for:
Read Committed
Dirty Read - NO
NonRepeatable Read - YES
Phantom - YES
What are the transaction isolation level effects for:
Repeatable Read
Dirty Read - NO
NonRepeatable Read - NO
Phantom - YES
What are the transaction isolation level effects for:
Snapshot
Dirty Read - NO
NonRepeatable Read - NO
Phantom - NO
What are the transaction isolation level effects for:
Serializable
Dirty Read - NO
NonRepeatable Read - NO
Phantom - NO
What is the syntax for changing the isolation level?
SET TRANSACTION ISOLATION LEVEL [Read Uncommitted, Read Committed, Repeatable Read, Snapshot, Serializable]
What is a heap?
A set of rows contained in pages that are connected through an Index Allocation Map, not indexed and not ordered.