Search

Monday, July 16, 2012

Remove Auto Shrink from all databases

Use below query to remove Auto Shrink from all database: 


DECLARE @DatabaseName varchar(100)  
DECLARE @AlterQuery varchar(500)  
  
DECLARE @CurDB CURSOR READ_ONLY FOR  
SELECT name FROM sys.databases WHERE database_id >  4 AND DATABASEPROPERTYEX(name, 'IsAutoShrink') = 1  
  
OPEN @CurDB  
FETCH NEXT FROM @CurDB INTO @DatabaseName  
WHILE @@FETCH_STATUS = 0  
    BEGIN  
    SET @AlterQuery ='ALTER DATABASE [' + @DatabaseName + '] SET AUTO_SHRINK OFF WITH NO_WAIT' + CHAR(10)  
    print @AlterQuery  
    EXEC(@AlterQuery)  
    FETCH NEXT FROM @CurDB INTO @DatabaseName  
    END  
  
CLOSE @CurDB  
DEALLOCATE @CurDB  

1 comment:

  1. I'm extremely pleased to find this site. I need to to thank you for your time due to this fantastic read!! I definitely savored every part of it and i also have you book marked to look at new stuff in your site.
    my web page: decaptchers

    ReplyDelete