Imagine you (or someone) fires a delete from very_important_table
in your production database. Sql Server happily deletes along, commits the transaction and would, as you suggest, "forget" about the transaction.
Later on someone will note the data is gone (after all this was your very_important_table
). You would be thankful in this situation Sql Server did not forget about the transaction so you can restore your database to the point in time just before the (unintentional) delete! At least (as mentioned) if you use the "Full Recovery" model.
This is among other things why the transaction log keeps all this information around.
Now, when would it be "safe" to chuck the log? After you made a backup - hahaa! Sql Server assumes that you keep your backup in a safe place and this means it does no longer have to hang on to the log. This is why you have to make a backup before you can shrink your transaction log.
But I believe that shrinking the transaction log should be something for emergencies. In normal operation you should "know" (or guess) how big the transaction log will get in a certain amount of time (read: in the intervals between log backups!) and assign it that much space (plus some headroom might be a good idea). Then you disable auto grow (or tweak it at least) and set an alert for when the transaction grows "too big" (let's say 80% of what you set as size if you gave it 50% or 100% headroom). Then you have time to react if something goes wrong.
Remember (as others wrote): the (log) backup will not "shrink" the log file, it just "empties" it. You will still see the same file size on the file system but there is free space in it (DBCC SQLPERF(logspace)
will show you this).
If you have auto grow enabled the log will just fill your disk without you knowing and when the disk is full - bam - nothing you can do (in the worst case not even backup or shrink the log!).
What I am trying to say is the following: this is not an easy topic. Be aware!
Maybe this Microsoft article will provide a starting point: How to Stop the transaction log of a SQL Server database from growing unexpectedly
Edit: Would this question be better suited for serverfault?