Module 15: Managing Transactions and LocksOverviewIntroduction to Transactions and LocksManaging TransactionsPowerPoint PresentationTransaction Recovery and CheckpointsConsiderations for Using TransactionsSetting the Implicit Transactions OptionRestrictions on User-defined TransactionsSQL Server LockingConcurrency Problems Prevented by LocksLockable ResourcesTypes of LocksLock CompatibilityManaging LocksSession-Level Locking OptionsDynamic Locking ArchitectureTable-Level Locking OptionsDeadlocksDisplaying Locking InformationRecommended PracticesReviewModule 15: Managing Transactions and LocksOverviewIntroduction to Transactions and LocksManaging TransactionsSQL Server LockingManaging LocksIntroduction to Transactions and LocksTransactions Ensure That Multiple Data Modifications Are Processed TogetherLocks Prevent Update ConflictsTransactions are serializableLocking is automaticLocks allow concurrent use of dataConcurrency Control Managing TransactionsMultimedia Presentation: SQL Server TransactionsTransaction Recovery and CheckpointsConsiderations for Using TransactionsSetting the Implicit Transactions OptionRestrictions on User-defined TransactionsMultimedia Presentation: SQL Server TransactionsTransaction Recovery and CheckpointsTime (and place in log)DatabaseTransaction LogTransaction LogINSERT …DELETE …UPDATE ……INSERT …DELETE …UPDATE ……INSERT …DELETE …UPDATE ……INSERT …DELETE …UPDATE ……INSERT …DELETE …UPDATE ……CHECKPOINTCRASH!!!COMMITCOMMITCOMMITRecovery Needed? NONERecovery Needed? NONERecovery Needed? ROLL FORWARDRecovery Needed? ROLL FORWARDRecovery Needed? ROLL BACKRecovery Needed? ROLL BACKRecovery Needed? ROLL FORWARDRecovery Needed? ROLL FORWARDRecovery Needed? ROLL BACKRecovery Needed? ROLL BACKZOT!Considerations for Using TransactionsTransaction GuidelinesKeep transactions as small as possibleUse caution with certain Transact-SQL statementsAvoid transactions that require user interactionIssues in Nesting TransactionsAllowed, but not recommendedUse @@trancount to determine nesting levelSetting the Implicit Transactions OptionAutomatically Starts a Transaction When You Execute Certain StatementsNested Transactions Are Not AllowedTransaction Must Be Explicitly Completed with COMMIT or ROLLBACK TRANSACTIONBy Default, Setting Is OffSET IMPLICIT_TRANSACTIONS ONSET IMPLICIT_TRANSACTIONS ONALTER DATABASEBACKUP LOGCREATE DATABASEDROP DATABASERECONFIGURERESTORE DATABASERESTORE LOGUPDATE STATISTICSRestrictions on User-defined TransactionsCertain Statements May Not Be Included in a Transaction SQL Server LockingConcurrency Problems Prevented by LocksLockable ResourcesTypes of LocksLock CompatibilityConcurrency Problems Prevented by LocksLost UpdateUncommitted Dependency (Dirty Read)Inconsistent Analysis (Nonrepeatable Read)Phantoms ReadsLockable Resources ItemItem DescriptionDescriptionRID Row identifierKey Row lock within an indexPageExtentTableData page or index pageGroup of pagesEntire tableDatabase Entire databaseTypes of LocksBasic LocksSharedExclusiveSpecial Situation LocksIntentUpdateSchemaBulk updateLock CompatibilityLocks May or May Not Be Compatible with Other LocksExamplesShared locks are compatible with all locks except exclusiveExclusive locks are not compatible with any other locksUpdate locks are compatible only with shared locksSession-Level Locking OptionsDynamic Locking ArchitectureTable-Level Locking OptionsDeadlocksDisplaying Locking Information Managing LocksSession-Level Locking Options Transaction Isolation LevelREAD COMMITTED (DEFAULT)READ UNCOMMITTEDREPEATABLE READSERIALIZABLELocking TimeoutLimits time waiting for a locked resourceUse SET LOCK_TIMEOUTDynamic Locking ArchitectureDynamicLockingTablePageRowCostGranularityLocking CostConcurrency CostTable-Level Locking OptionsUse with CautionCan Specify One or More Locking Options for a TableUse optimizer_hints Portion of FROM Clause inSELECT or UPDATE StatementOverrides Session-Level Locking OptionsDeadlocksHow SQL Server Ends A DeadlockHow to Minimize DeadlocksHow to Customize the Lock Time-Out SettingDisplaying Locking InformationCurrent Activity Windowsp_lock System Stored ProcedureSQL ProfilerWindows 2000 System MonitorAdditional InformationRecommended PracticesDesign Transactions to Minimize DeadlocksDesign Transactions to Minimize DeadlocksUse SQL Server Defaults for LockingUse SQL Server Defaults for LockingKeep Transactions ShortKeep Transactions ShortBe Careful When You Use Locking OptionsBe Careful When You Use Locking OptionsReviewIntroduction to Transactions and LocksManaging TransactionsSQL Server LockingManaging
View Full Document