Forked from muratvezir/gist:4ddd26cfa9341c4f2d9286957a4226c2
Created
June 21, 2022 07:34
-
-
Save kad1r/00bb97f8da213054a4ce91def0a9ab4c to your computer and use it in GitHub Desktop.
T-Sql Leaped Shink
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
declare @from int | |
declare @leap int | |
declare @to int | |
declare @datafile varchar(128) | |
declare @cmd varchar (512) | |
/*settings*/ | |
set @from = 200000 /*Current size in MB*/ | |
set @to = 180000 /*Goal size in MB*/ | |
set @datafile = 'TESTDB' /*Datafile name*/ | |
set @leap = 500 /*Size of leaps in MB*/ | |
print '--- SATS SHRINK SCRIPT START ---' | |
while ((@from - @leap) > @to) | |
begin | |
set @from = @from - @leap | |
set @cmd = 'DBCC SHRINKFILE (''' + @datafile +''', ' + cast(@from as varchar(20)) + ')' | |
print @cmd | |
exec(@cmd) | |
print '==> SATS SHRINK SCRIPT - '+ cast ((@from-@to) as varchar (20)) + 'MB LEFT' end | |
set @cmd = 'DBCC SHRINKFILE (''' + @datafile +''', ' + cast(@to as varchar(20)) + ')' | |
print @cmd | |
exec(@cmd) | |
print '--- SATS SHRINK SCRIPT COMPLETE ---' | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment