|
|
|
|
|
|
|
|
|
Shrinking the Transaction Log with SMO
This videos shows you how to shrink the transaction log of a database using SMO.
|
|
|
|
Duration:
|
3
mins
6
secs
|
|
Skill Level:
|
200
|
|
Rating:
|
4.01
out of 5
|
|
Publish Date:
|
September 10, 2008
|
|
|
|
About the Author
|
|
Tim Mitchell is a Microsoft SQL Server database developer, business intelligence consultant, writer, and speaker. He has been working professionally with SQL Server for over six years, and holds the MCTS and MCDBA certifications from Microsoft as well as a Bachelor's degree in computer science from Texas A&M University - Commerce.
|
|
References
|
|
Comments
|
Glenn Thompson on
10/22/2008
You are assuming a person knows how to use SMO, but us part time DBAs usually just fly by the seat of our pants when it comes to anything DBA related. :)
|
|
John Farner on
10/22/2008
This is a very effective method for content delivery. Could you add a "download code" button?
|
|
|
John, we're working on it. The code should be available soon.
|
|
|
Hi there,
Your code works wonders.
However, I think you might have a typo in your demo.
foreach (Database db in svr.Databases)
{
foreach (LogFile log in db.LogFiles)
{
//truncate log file only if more than 50% of its declared size is used
if ((log.UsedSpace / log.Size) > 0.5)
{
//optimal size of log file is 20% the size of its database
log.Shrink(Convert.ToInt32(db.Size * 0.2), ShrinkMethod.Default);
I think it should be
if ((log.UsedSpace / log.Size) > 0.5)
instead of if ((log.UsedSpace / log.Size) < 0.5)
Anyway, if I am wrong at this, I will find out. Still, it looks good in a development server.
Also, recommended log file size is 20% of database size. That is why, I used
log.Shrink(Convert.ToInt32(db.Size * 0.2), ShrinkMethod.Default);
Best regards,
Tonci.
|
|
|
More details on building script.
|
|
|
Slick!
|
Must Be Logged In
|
|
|
|
|