Tuesday, September 14, 2010

Scripts to Shrink Database

Hi,

If your database log size is increased, then if you want to shrink the database using script. check the following script.

DECLARE @DBName varchar(100)DECLARE
SET
select
@getDB CURSOR @getDB = CURSOR FOR name from master.sys.databases where len(owner_sid)>4OPEN @getDBFETCH
FROM
NEXT @getDB INTO @DBNameWHILE @@FETCH_STATUS = 0BEGIN
exec
set recovery simple'
('alter database ' + @DBName + ')exec('dbcc ShrinkDatabase(' + @DBName + ')')FETCH
FROM
NEXT @getDB INTO @DBNameEND
CLOSE
@getDBDEALLOCATE @getDB

No comments:

Post a Comment