How many log files can a database have?

  • In my memory, a database can only have one log file. However, I just saw one database containing 2 log files! Any input will be greatly appreciated.

  • You can have multiple log files.  If I remember correctly, if the first log file fills up, then the second one will be used. 

    Aunt Kathi Data Platform MVP
    Author of Expert T-SQL Window Functions
    Simple-Talk Editor

  • I ran out of space at file 1069...  But I guess this is just enough of what you need to know :

    USE Master

    GO

    CREATE DATABASE MaxLogCnt

    GO

    DECLARE @i AS INT

    DECLARE @SQL AS VARCHAR(8000)

    SET @i = 1

    WHILE @i <= 1250

     BEGIN

      SET @SQL = 'ALTER DATABASE MaxLogCnt ADD LOG FILE (NAME = MaxLogCnt' + CONVERT(VARCHAR(10), @i) + ', FILENAME = ''C:\Program Files\Microsoft SQL Server\MSSQL$DEVELOPPEMENT\Data\MaxLogCnt' + CONVERT(VARCHAR(10), @i) + 'log.ldf'', SIZE = 1MB,  MAXSIZE = 100MB,  FILEGROWTH = 1MB)'

      PRINT @SQL

      EXEC (@SQL)

      SET @i = @i + 1

     END

    GO

    --DROP DATABASE MaxLogCnt

    GO

  • Max files per DB (from BOL) : 32767

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

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