TLog Shrink T-SQL Command

  • Dear,

    I have the following codes to shrink my log file. But I dont know the difference of these two codes. Would you please explain to me that which is the effective one?

    1.

    USE myDB

    GO

    DBCC SHRINKFILE ('myDB_Log', 1)

    BACKUP LOG myDB WITH TRUNCATE_ONLY

    DBCC SHRINKFILE ('myDB_Log', 1)

    GO

    2.

    GO

    alter database myDB

    set recovery simple;

    GO

    dbcc shrinkfile (myDB_log, 1);

    GO

    alter database myDB

    set recovery full;

    GO

    use myDB;

    Thank You

    Regards,

    Akbar

  • The first one won't work on SQL 2008, the second one will. Otherwise they're the same, both bad forms of log mismanagement.

    Please read through this: http://www.sqlservercentral.com/articles/Administration/64582/

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (11/10/2012)


    The first one won't work on SQL 2008, the second one will. Otherwise they're the same, both bad forms of log mismanagement.

    Please read through this: http://www.sqlservercentral.com/articles/Administration/64582/

    Would you please tell me that why do dbcc shrinkfile (myDb_log, 1); is used in between set recovery simple and set recovery full?

  • The DBCC is the one that actually shrinks the log file.

    Please go and read that article.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply