SQLServerCentral.com / SQL Server 2012 / SQL 2012 - General / Tranaction Logs on a Test Box / Latest PostsInstantForum.NET v2.9.0SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comTue, 31 Mar 2015 15:35:01 GMT20RE: Tranaction Logs on a Test Boxhttp://www.sqlservercentral.com/Forums/Topic1555938-2799-1.aspxOr, as something a tad easier:[code="sql"] exec sp_MSforeachDB 'USE [?]; IF ''?'' NOT in (''master'',''model'',''msdb'',''tempDB'') DBCC ShrinkFile(2,10)'[/code]Untested, so may have syntax errors. Test before use.Shrinkfile takes either the file name or the file ID as the first parameter, and the first log file is always file ID 2 (and if you have more than one log file, that needs fixing)Mon, 31 Mar 2014 15:19:00 GMTGilaMonsterRE: Tranaction Logs on a Test Boxhttp://www.sqlservercentral.com/Forums/Topic1555938-2799-1.aspxThanks GSC_DBAThat is really Great!! I tried using MS_ForEachDatabase, but could not get it working correctly. I was missing something in the dynamic code, and could not get it correct.I will give this a try and see if this works. It looks better than what I have written :)I greatly appreciate your time, code, comment and suggestion.Andrew SQLDBAMon, 31 Mar 2014 11:33:18 GMTAndrewSQLDBARE: Tranaction Logs on a Test Boxhttp://www.sqlservercentral.com/Forums/Topic1555938-2799-1.aspxHey LowellYes, in fact they are already in Simple recovery mode. But with the amount of data being pumped int at times, they can grow. And over time, they get big. Not large, just big, and I was asked to do what I can do to save as much drive space as possible. On this box, 10 - 15GB is a nice amount of drive space.Thanks for your suggestions, comments and answer to my questionAndrew SQLDBAMon, 31 Mar 2014 11:30:23 GMTAndrewSQLDBARE: Tranaction Logs on a Test Boxhttp://www.sqlservercentral.com/Forums/Topic1555938-2799-1.aspxAndrew in my shop, all databases on development boxes are switched over to simple recovery mode; i don't need a point in time restore on development that log backups would provide me; would it be an option to change them to simple recovery and shrink the logs once, isntead of letting them remain in full recovery?Mon, 31 Mar 2014 10:30:04 GMTLowellRE: Tranaction Logs on a Test Boxhttp://www.sqlservercentral.com/Forums/Topic1555938-2799-1.aspxHi Andrew,I have created this for you from a similar maintenance task I undertake:[code="sql"]EXEC sp_MSforeachdb 'IF ''?'' NOT IN (''tempDB'',''model'',''msdb'', ''master'')BEGIN DECLARE @desiredSizeInMB INT = 16, @execSQL NVARCHAR(MAX) SELECT @execSQL = ''DBCC SHRINKFILE ('' + NAME + '' ,'' + CAST(@desiredSizeInMB AS VARCHAR(4)) + '' ) WITH NO_INFOMSGS;'' FROM [?].[sys].[database_files] AS DF WHERE [type] = 1 use [?]; EXEC sp_executesql @execSQLEND'[/code]Edited - actually execute the SQL!:-)Mon, 31 Mar 2014 10:19:12 GMTgsc_dbaTranaction Logs on a Test Boxhttp://www.sqlservercentral.com/Forums/Topic1555938-2799-1.aspxHello Everyone, and Happy Friday!I am doing some general housekeeping for a couple of our SQL boxes in the Development environment. All the databases are set to Simple recovery mode. No need in anything else for these boxes. I have a database on all the boxes named "DatabaseMaintenance" Keeps things like all the sprocs for any type of database maintenance, etc....I would like to schedule a single sproc that is located in the DatabaseMaintenance database to shrink the Transaction logs on a set schedule. They sometimes grow quite large while testing and developing. The thing that I cannot seem to get around, is when using the ShrinkFile command, one must use the Log Name. If this code is in a sproc that is located in the DatabaseMaintenance database, it will fail when attempting to call out to a different database. Because the Log does not exist on the database that the sproc is located.How can I get around this small dilemma? There are only about 10 databases per box. To a point we really do not care what happens to them. They are on a Full backup schedule daily, just to keep the objects. As I stated previously, the logs will still grow huge at times while pumping data.Is there a way to create a piece of code that will run against each database on the server, and be stored in a single database? Other than the system databases of course.Thank you in advance for all your assistance, suggestions and comments.Andrew SQLDBAFri, 28 Mar 2014 08:15:28 GMTAndrewSQLDBA