DBCC SHRINKFILE

  • Hello,

    Is there way that  I can use database name within DBCC ShrinkFile ?

    DBCC SHRINLFILE(Datrabasename..Logname)?

    Thanks

  • This was removed by the editor as SPAM

  • From books online:

    DBCC SHRINKFILE applies to the files in the current database. Switch context to the database to issue a DBCC SHRINKFILE statement referencing a file in that particular database. For more information about changing the current database, see USE.

     

    This would lead me to believe that you can't use a database name within the DBCC SHRINKFILE command itself, but you could easily tack on a use statement before the command.

    USE pubs

    GO

    DBCC SHRINKFILE(customers, 10000)

     

    Would it be possible to do it this way?

  • Farhad, Mister Sachmo's example might be a little confusing. Note the "customes" in the example is the logical file name not a table.

    From BOL the syntax is as follow:

    DBCC SHRINKFILE

    (

        { 'file_name' | file_id }

        { [ , EMPTYFILE ]

        | [ [ , target_size ] [ , { NOTRUNCATE | TRUNCATEONLY } ] ]

        }

    )

    [ WITH NO_INFOMSGS ]

    The 'file_name' argument is the "logical name" of the file to be shrunk.

    Therefore, his/hers example could be like:

    USE pubs

    GO

    DBCC SHRINKFILE(pubs, 7)

    DBCC SHRINKFILE(pubs_Log, 2)

    This reduces the size of pubs.mdf to 7MB, if possible. The second command reduces the size of pubs.ldf to 2MB.  

    To find the logical name, you can use sp_HelpFile:

    USE Test

    Go

    sp_HelpFile

    Go

    For more information and examples refer to:

    http://msdn2.microsoft.com/en-us/library/ms189493.aspx

     

  • Thank you

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

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