Welcome back. In Lesson 4, you learned how tables connect through relationships and how foreign keys enforce
referential integrity. That keeps your data consistent across tables.
Now we’re going to study the feature that makes SQL Server reliable for real businesses:
transactions. Transactions are the reason banks, hospitals, airports, ecommerce sites, and scheduling systems
can trust their databases even when errors happen, servers restart, or thousands of users are active at once.
Lesson description: You will learn what a transaction is, what ACID means in real production systems,
how SQL Server guarantees durability through the transaction log, how concurrency and isolation affect correctness,
and the most common transaction mistakes that cause blocking, deadlocks, inconsistent results, and performance incidents.
A transaction is a group of operations that SQL Server treats as a single unit of work.
The key idea is simple:
either all changes succeed together, or none of them do.
This protects the business from “half-finished” updates that would produce incorrect information.
If step 3 fails but step 2 succeeds, your data becomes incorrect. A transaction prevents this by ensuring
the database either commits everything or rolls everything back.
ACID is the reliability contract a database provides during transactions:
If any part of the transaction fails, SQL Server rolls back the changes.
That prevents partial updates and protects business correctness.
After the transaction commits, the database must still obey constraints and relationships.
Primary keys must be unique, foreign keys must be valid, CHECK constraints must pass.
If a transaction would violate these rules, SQL Server rejects it.
Isolation controls how transactions interact when many users are active at the same time.
This is where locking, blocking, and deadlocks come from.
The database must protect correctness without destroying performance.
Once SQL Server commits a transaction, it guarantees that change will survive crashes and restarts.
This is achieved through the transaction log.
DBA reality: When a company says “we lost data,” that is usually a durability failure caused by
missing backups, broken log chains, storage issues, or mismanaged recovery strategies—not because SQL Server “forgot.”
SQL Server does not write your changes directly to disk as “final truth” immediately.
Instead, it records changes in the transaction log first, then flushes that log to disk.
This is called Write-Ahead Logging (WAL).
What you must understand:
SQL Server can recover committed transactions because the log contains the instructions needed to redo changes,
and it can undo uncommitted changes using the log as well.
You will go much deeper into log internals in Section 6, but you need the concept now.
In SQL Server, many operations run in auto-commit mode by default:
a single statement commits automatically if it succeeds.
DBAs and developers also use explicit transactions when multiple statements must succeed together.
Explicit transactions are powerful, but if you keep them open too long, they can cause:
blocking, deadlocks, and massive performance slowdowns.
One long transaction can impact hundreds of users.
In a multi-user system, transactions overlap. SQL Server must keep data correct while multiple sessions read and write.
That requires locks or row versioning (depending on configuration).
DBA mindset: Transactions are not just about correctness—they are also about performance.
When you troubleshoot slowness in production, you often discover the root cause is transaction behavior:
long-running updates, uncommitted work, or poor isolation patterns.
A transaction starts, updates rows, and then the session “hangs” or the developer forgets to commit/rollback.
Other sessions pile up behind it waiting for locks.
Symptoms: slow application, timeouts, many blocked sessions, angry users.
A single transaction updates millions of rows. This can cause massive log growth, long lock durations,
and long recovery times after restart.
DBA best practice: batch large changes (controlled chunks), especially in production.
If an error occurs and the script does not handle it correctly, you may leave open transactions
or produce partial business outcomes at the application level.
Some systems choose isolation levels that create too much blocking or allow inconsistent reads.
DBAs must balance correctness and performance.
A commit guarantees SQL Server can recover the change after a crash.
It does not protect you from:
accidental deletes, ransomware, or human mistakes.
That is why backups and restore testing are mandatory (Section 9).
In real DBA work, you don’t guess. You collect evidence. Transaction problems usually show up as:
Later in the course (monitoring and troubleshooting), you will build a script pack that shows:
who is blocking whom, what query is running, and how long the transaction has been open.
In the next lesson, you will learn how to design tables so data stays consistent and easy to maintain.
We will cover normalization levels in a practical DBA way, show where over-normalization hurts performance,
and explain when controlled denormalization is acceptable in real production systems.
Not a member yet? Register now
Are you a member? Login now