sp_msforeachdb
to loop through all the databases, checking for recovery model, and running a [DBCC SHRINKFILE][1] command. * roll your own loop - less Dynamic SQL required The script for the latter option might look like: DECLARE @TheBigShrink NVARCHAR(MAX) SELECT @TheBigShrink = N'' SELECT @TheBigShrink = @TheBigShrink + 'USE [' + DB_NAME(dbid) + '] DBCC SHRINKFILE (N''' + name + ''', 1) ' FROM sysaltfiles WHERE fileid = 2 AND dbid IN ( SELECT database_id FROM sys.databases WHERE recovery_model_desc = 'SIMPLE' AND database_id > 4 ) SELECT @TheBigShrink --EXEC (@TheBigShrink) -- uncomment this line when happy with the output. [1]:
http://technet.microsoft.com/en-us/library/ms189493.aspx
15 People are following this question.