Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15694

Script to Loop through each DB

$
0
0

Hello,

I'm not very good with scripting loops.

I want to loop through each database and check the LogFile Size and Free Space on Log File.

If it meets these conditions I want to truncate.

If @logsize >= 20000 -- and @logspace >= 80  
set @SQL = 'use'  + [Database_Name]  +  'dbcc shrinkfile ([LogFileName], 20000, TRUNCATEONLY) WITH NO_INFOMSGS'
exec (@SQL)

Please help


Viewing all articles
Browse latest Browse all 15694

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>