DBCC SHRINKDATABASE()

  • Is there any way to calculate how long it will take to do a DBCC SHRINKDATABASE('DBName', 0, NOTRUNCATE) command.

    I have a 1+ terabyte database I'd like to propose be shrunk but without releasing dataspace back to the operating system.

    Is it even worthwhile doing so?

    Thanks in advance,

  • What do you try to achieve? Instead shrink the database, you can shrink each files of the database once at a time.

  • How can I use DBCC SHRINKFILE within a procedure , so I should be able to pass the databasename and log name. Can this be done?

    If I were to use DBCC SHRINKFILE how can I specify databasename within the DBCC?

    Any idea would be helpful.

    Thank

  • Thanks

  • If you want you can pass fileid or filename and size.

    declare @sql Varchar(1000), @db sysname

    select @db = 'pubs'

    select @sql = 'use '+@db+' DBCC SHRINKFILE (1, 1000)'

    EXEC( @sql)

     

    MohammedU
    Microsoft SQL Server MVP

  • you say you don't want to return space back to o/s - is this correct? So is what you're asking how you can shrink the physical data storage part of your database?

    You have the data part of your database ( file(s) and group(s) )

    You have the t log

    Both will have free ( working ) space and both will have the data space used - what exactly do you wish to do - reduce the free ( working ) space  or the actual data ?

    [font="Comic Sans MS"]The GrumpyOldDBA[/font]
    www.grumpyolddba.co.uk
    http://sqlblogcasts.com/blogs/grumpyolddba/

  • Thanks

Viewing 7 posts - 1 through 6 (of 6 total)

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