log file shrink script

Hello friends, I have posted a script earlier and this is the other one. And please this is not a respost  just want to make sure I am doing the right think. This script shrinks my log (ldf) files to 10.00 MB. But I do not find where should I make changes to the script and it should only shrink to 50 MB. And if someone has a better script then please give me.  Your help is really appreciated.
use master
DECLARE @Statement varchar (2000)

SELECT @Statement = ''
SELECT @Statement = @Statement + 'USE ?; '
SELECT @Statement = @Statement + 'SELECT ''?''; '
SELECT @Statement = @Statement + 'DECLARE @Log_Logical_FileName varchar (30); '
SELECT @Statement = @Statement + 'SELECT @Log_Logical_FileName = rtrim(name) FROM dbo.sysfiles WHERE (status & 0x40) <> 0; '
SELECT @Statement = @Statement + 'dbcc shrinkfile (@Log_Logical_FileName, 51200,truncateonly); '
SELECT @Statement = @Statement + 'SELECT fileid, name, filename, size, growth, status, maxsize FROM dbo.sysfiles WHERE (status & 0x40) <> 0; '
SELECT @Statement

EXEC sp_MSforeachdb @command1=@Statement
GO
aatishpatelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RiteshShahCommented:
there is no problem in shrinking, why do you want it to shrink to 50MB? is there any specific reason?

0
RiteshShahCommented:
btw, try using this one.



use master 
DECLARE @Statement varchar (2000)
 
SELECT @Statement = ''
SELECT @Statement = @Statement + 'USE ?; '
SELECT @Statement = @Statement + 'SELECT ''?''; '
SELECT @Statement = @Statement + 'DECLARE @Log_Logical_FileName varchar (30); '
SELECT @Statement = @Statement + 'SELECT @Log_Logical_FileName = rtrim(name) FROM dbo.sysfiles WHERE (status & 0x40) <> 0; '
SELECT @Statement = @Statement + 'dbcc shrinkfile (@Log_Logical_FileName, 51200); '
SELECT @Statement = @Statement + 'SELECT fileid, name, filename, size, growth, status, maxsize FROM dbo.sysfiles WHERE (status & 0x40) <> 0; '
SELECT @Statement 
 
EXEC sp_MSforeachdb @command1=@Statement
GO

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aatishpatelAuthor Commented:
so ritesh that would shrink it to 50 MB right ?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

aatishpatelAuthor Commented:
and we hab=ve to shrink the drive is small and no chances to replace the big drive.
0
RiteshShahCommented:
it suppose to. isn't it? actually this is something we can't control 100% I guess, if you have some active transaction which still needs space, it won't get truncated.
0
RiteshShahCommented:
>>and we hab=ve to shrink the drive is small and no chances to replace the big drive.<<

than why 50MB, what makes any difference if it become even 1MB. is there any specific reason you want it to be 50MB only?
0
chapmandewCommented:
You'll NOT be able to shrink it if there are inactive transactions taking up space.  Do a log backup first.

http://sqlservernation.com/blogs/admin/archive/2009/05/17/why-is-my-log-file-so-big.aspx
0
aatishpatelAuthor Commented:
thanx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.