Skip to content

Instantly share code, notes, and snippets.

@othtim
Last active December 23, 2015 11:01
Show Gist options
  • Select an option

  • Save othtim/6625455 to your computer and use it in GitHub Desktop.

Select an option

Save othtim/6625455 to your computer and use it in GitHub Desktop.
shrink dbs
# 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
@othtim

othtim commented Mar 31, 2014

Copy link
Copy Markdown
Author

never do this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment