Saturday, June 11, 2016

Shrink all databases log file at a time

drop table #f
go
create table #f (name sysname, fileid int, filename sysname, filegroup sysname null,
size sysname, maxsize sysname, growth sysname, usage sysname)
go
exec sp_MSforeachdb 'declare @s varchar(MAX); use [?];
truncate table #f; INSERT #f (name, fileid, filename, filegroup, size, maxsize, growth, usage )
exec sp_helpfile
--select * from #f

 select @s = ''use [?]; DBCC SHRINKFILE ('' + name +'',0,truncateonly )'' from #f where usage = ''log only''
print @s'

No comments:

Post a Comment