I started to write a reply to lockes, who was asking about why we need a transaction log. It was long enough, so I figured I'd share it here.
The transaction log is perhaps one of the most misunderstood parts of SQL Server's architecture, and is one of the most integral components of each database.
Why do we need a transaction log? Consider the ACID properties of transactions: Atomicity, Consistency, Isolation, Durability (http://en.wikipedia.org/wiki/ACID). Durability is the property that the transaction log assists us with - "once a transaction has been committed, it will remain so." The effect of this, is once your database engine tells you that the transaction is complete, it HAS to stay that way. This means that the transaction must be stored on disk, otherwise, if you have a power failure and your change was only in memory on the database server, you may restart your database engine and find that your change wasn't persisted.
OK, so we have to write the changes to disk before we can return a successful commit back to the application. A SQL Server database stores its rows on 8 KB pages, which can be laid out anywhere in the data file (.mdf or .ndf file extensions). A page can hold many rows (if each row is 20 bytes, you can fit about 400 rows on the page). Pages are the smallest unit of reading and writing, so if you modify one row on the page, the entire 8 KB page is written back to disk.
Imagine if you update 100 rows in a single transaction (UPDATE Products SET Price = Price + 1). Some of these rows could be at the start of the data file, some in the middle, and some at the end. You would need to drag the disk head to each position on the disk, write the updated page to disk (an 8 KB write), and move onto the next location, waiting for the disk to spin, and the disk head to move each time.
Enter the transaction log. Instead of making a randomly placed 8 KB write for each page that needs changing, the transaction log is a sequential file, capable of writing in 512 byte sectors (a sector being the smallest sized disk write operation). As it's sequential, you don't need to wait for the disk head to move to the next position to write the next change - the next position is already right under the disk head. This means you can lay the changes down on disk very rapidly, which keeps the end user happy.
While we are writing the change to the transaction log, we're also updating the in-memory version of the data page. Later on, a process named the Lazy Writer will come and commit these "dirty" data pages to disk. If you lose power, then all the dirty data pages in memory will be lost, but we have a record of all changes that occurred in the database. Each operation in the transaction log has a Log Sequence Number (LSN), which is like the odometer in your car - it's a unique, ever increasing number. Each data page records which LSN was last used on that page, and when the database starts up, it will scan through the transaction log, and check to see that each operation in the log has been changed on the data page (i.e., the Lazy Writer successfully wrote that page back to disk). If it hasn't, the change is made to the data page again (not re-written to the transaction log). The end result is that the database is back in a consistent state.
Note that we can also rollback a transaction. This is controlled by the transaction log storing the previous value as well as the changed value. If the transaction is rolled back, the transaction log is read to get the previous value, and a new transaction log record is written to say that the row has been changed to the old value (in case the uncommitted value has been stored back to disk by the Lazy Writer- imagine a very long transaction of minutes or hours).
To re-iterate, the two main reasons for the transaction log are:
Performance
Durability
So, the transaction log is simply a list of all changes that have occurred in the database, whether data changes (as in our UPDATE example), or structural changes (grow a data file, or create new objects). This also gives us the ability to replay any operation that occurred in the database. If we take a copy of the database (a full backup), and then have copies of the transaction log from that point on, we can replay every operation and bring the database back to a consistent state at any point in time. For example, if you accidentally dropped a table, you can bring the database back to the point just before (either by a time (2:45pm), or by a specific LSN), and recover the data.
Another option is the concept of "log shipping". This is where you take your transaction log backups, and routinely (every few minutes) restore them onto another server. In the event of a distaster, you have a warm standby copy of the database ready to bring online.
This is a good place to take a rest.
To avoid running out of space, the transaction log needs to be reused at some point. At what point? How do we trigger this? This leads us to the concept of database recovery models, and the two most common are the "Full" recovery model and the "Simple" recovery model.
The Full recovery model puts all control onto the DBA. When you backup the transaction log, it will write the as-yet-un-backed-up log records to a backup file, and then remove ("truncate") the log. It will only truncate the log back to the point of the earliest open transaction, because it may need all the log records to roll back this transaction after the backup. If you don't back up the transaction log while in the Full recovery model, your log will continue to grow until you run out of space.
The Simple recovery model makes every thing easy. You don't back up the transaction log. When the log runs a "checkpoint" operation (triggered either by the DBA running "CHECKPOINT", or the log reaching 70% full), all dirty pages are flushed to disk, and the transaction log will be truncated (again, up to the point of the earliest open transaction). As you are not taking backups of the transaction log, you have no ability to restore to a specific point in time, as you don't have a complete log chain from the time of a full backup. The Simple transaction log only stores enough information to recover in the event of a loss of power.
There is another recovery model, Bulk Logged, which is similar to Full, but used when loading a large amount of data. It will log the changed extents (an extent is 8 pages, or 64 KB). This can be a lot more efficient than logging "now change this row, now change this row, now change this row", which could add up to more than 64 KB inside the log.
Sorry for the length - transaction logs are a complicated topic, and it's hard to get just the right amount of internal detail vs concepts! Any questions or comments?