Download presentation
Presentation is loading. Please wait.
Published byMelanie Lawson Modified over 8 years ago
1
Module 14: Managing Transactions and Locks
2
Overview Introducing Transactions and Locks Managing Transactions Understanding SQL Server Locking Architecture Managing Locks
3
Lesson: Introducing Transactions and Locks What Are Transactions and Locks? What Is Concurrency Control?
4
What Are Transactions and Locks? Transactions Ensure That Multiple Data Modifications Are Processed Together Locks Prevent Update Conflicts Transactions are serializable Locking is automatic Locks allow concurrent use of data
5
What Is Concurrency Control? Pessimistic Locks data when data is read in preparation for an update Other users are blocked until lock is released Use where high contention for data exists Optimistic Locks data when an update is performed Error received if data was changed since initial read Use when low contention for data exists
6
Lesson: Managing Transactions Multimedia Presentation: SQL Server Transactions How Transaction Recovery Works Considerations for Using Transactions The Implicit Transactions Option Restricted Statements
7
Multimedia Presentation: SQL Server Transactions Concepts covered in this presentation: SQL Server Transaction Processing Two Types of Transactions Implicit Explicit Rolling Back a Transaction The Transaction Log Checkpoints The Automatic Recovery Process
8
How Transaction Recovery Works Transaction RecoveryAction Required None CheckpointSystem Failure Roll forward Roll back Roll forward Roll back 1 1 2 2 3 3 4 4 5 5
9
Considerations for Using Transactions Transaction Guidelines Keep transactions as short as possible Use caution with certain Transact-SQL statements Avoid transactions that require user interaction Issues in Nesting Transactions Allowed, but not recommended Use @@trancount to determine nesting level
10
The Implicit Transactions Option Automatically Starts a Transaction When You Execute Certain Statements Nested Transactions Are Not Allowed Transaction Must Be Explicitly Completed with COMMIT or ROLLBACK TRANSACTION By Default, Setting Is Off SET IMPLICIT_TRANSACTIONS ON
11
ALTER DATABASE BACKUP LOG CREATE DATABASE DROP DATABASE RECONFIGURE RESTORE DATABASE RESTORE LOG UPDATE STATISTICS Restricted Statements Certain Statements May Not Be Included
12
Lesson: Understanding SQL Server Locking Architecture What Concurrency Problems Are Prevented by Locks? Lockable Resources Types of Locks Lock Compatibility
13
What Concurrency Problems Are Prevented by Locks? Lost Update Uncommitted Dependency (Dirty Read) Inconsistent Analysis (Nonrepeatable Read) Phantom Reads
14
Lockable Resources ItemDescription RID Row identifier Key Row lock within an index Page Data page or index page Extent Group of pages Table Entire table Database Entire database
15
Types of Locks Basic Locks Shared Exclusive Special Situation Locks Intent Update Schema Bulk update
16
Lock Compatibility Locks May or May Not Be Compatible with Other Locks Examples Shared locks are compatible with all locks except exclusive Exclusive locks are not compatible with any other locks Update locks are compatible only with shared locks
17
Session-Level Locking Options What Is Dynamic Locking Architecture? What Are Table-Level Locking Options? What Are Deadlocks? Methods to View Locking Information Best Practices Lesson: Managing Locks
18
Session-Level Locking Options Transaction Isolation Level READ UNCOMMITTED READ COMMITTED (default) REPEATABLE READ SERIALIZABLE Locking Timeout Limits time waiting for a locked resource Use SET LOCK_TIMEOUT
19
What Is Dynamic Locking Architecture? Dynamic Locking TablePageRow Cost Granularity Locking Cost Concurrency Cost Locking Cost Concurrency Cost
20
What Are Table-Level Locking Options? Use with Caution Can Specify One or More Locking Options for a Table Use optimizer_hints Portion of FROM Clause in SELECT or UPDATE Statement Overrides Session-Level Locking Options
21
What Are Deadlocks? How SQL Server Ends a Deadlock How to Minimize Deadlocks How to Customize the Lock Time-Out Setting
22
Methods to View Locking Information Current Activity Window sp_lock System Stored Procedure SQL Profiler Windows 2000 System Monitor Additional Information
23
Best Practices Be Careful When You Use Locking Options Use SQL Server Defaults for Locking Design Transactions to Minimize Deadlocks Keep Transactions Short
24
Lab A: Managing Transactions and Locks Exercise 1: Creating and Executing a Transaction Exercise 2: Rolling Back a Transaction Exercise 3: Viewing Locking Information Exercise 4: Setting Locking Options
25
Course Evaluation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.