Created
December 27, 2017 07:43
-
-
Save Ogacha/a86c113cce73dcf8673be8808fb97641 to your computer and use it in GitHub Desktop.
SQL Server 用 全DBのログ圧縮
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create procedure dbo.ログ圧縮 as begin | |
-- 全DB のログ圧縮 | |
declare @T table(SQL nvarchar(MAX)); | |
insert @T select N'USE ['+name+']; | |
declare @log sysname; | |
select @log=name from sys.database_files where type=1; | |
DBCC SHRINKFILE (@log, 0, TRUNCATEONLY);' | |
from sys.databases where database_id>=7 and state=0; | |
declare SQL cursor for select * from @T; | |
declare @SQL nvarchar(MAX); | |
open SQL; | |
ループ: | |
fetch next from SQL into @SQL; | |
if @@FETCH_STATUS<>0 goto おしまい | |
print @SQL; | |
exec sp_executesql @SQL; | |
goto ループ; | |
おしまい: | |
close SQL; | |
deallocate SQL; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment