Last active
December 23, 2015 11:01
-
-
Save othtim/6625455 to your computer and use it in GitHub Desktop.
shrink dbs
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
| # never do this | |
| declare @db varchar(255) | |
| declare c cursor for | |
| select name from sys.databases where is_read_only=0 and state=0 | |
| and name not in ('master','model','tempdb','msdb') | |
| open c | |
| fetch c into @db | |
| while @@fetch_status=0 | |
| begin | |
| --set recovery mode to SIMPLE | |
| exec SP_dboption @db,'trunc. log on chkpt.','true' | |
| --backup the DB to shrink the log | |
| BACKUP DATABASE @db TO DISK = N'D:\Data\SQL Backup\test.bak' WITH NOFORMAT, INIT | |
| --shrink | |
| DBCC shrinkdatabase (@db) | |
| fetch next from c into @db | |
| end | |
| close c | |
| deallocate c |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
never do this