Home All Groups Group Topic Archive Search About

SQL 2005: Shrinking DB files

Author
29 Nov 2007 6:26 PM
Conan Kelly
Hello all,

SSMS>Object Explorer>right-click a DB>Tasks>Shrink>Files
    File Type:.....Data
    Click "Reorganize pages before...." optioni
    Shrink file to:........1 MB

As soon as I tab out of the "Shrink file to:" text box, it automattically
adjusts to the smallest possible size the data file can be shrunk to (260 MB
in this case).

Then when I "Script Action to New Query Window", I get the following script:

    USE [DB Name]
    GO
    DBCC SHRINKFILE (N'DB Name_Data' , 260)
    GO

My question is, if I change the DBCC SHRINKFILE statment the following and
try to run it:

    DBCC SHRINKFILE (N'DB Name_Data' , 1)

What will the results be?  Will it fail and give errors?  Will it shrink the
file to the smallest possible size (260 MB)?  Will it try to shrink the file
to 1 MB thus losing/corrupting my data?

Thanks for any help anyone can provide,

Conan Kelly

Author
29 Nov 2007 6:42 PM
Ben Nevarez
It will try to shrink the file to the smallest size possible (it is not even
guaranteed that will shrink the size to 260 MB).

But you are not going to receive errors or lost or corrupt any data.

Hope this helps,

Ben Nevarez
Senior Database Administrator
AIG SunAmerica



Show quote
"Conan Kelly" wrote:

> Hello all,
>
> SSMS>Object Explorer>right-click a DB>Tasks>Shrink>Files
>     File Type:.....Data
>     Click "Reorganize pages before...." optioni
>     Shrink file to:........1 MB
>
> As soon as I tab out of the "Shrink file to:" text box, it automattically
> adjusts to the smallest possible size the data file can be shrunk to (260 MB
> in this case).
>
> Then when I "Script Action to New Query Window", I get the following script:
>
>     USE [DB Name]
>     GO
>     DBCC SHRINKFILE (N'DB Name_Data' , 260)
>     GO
>
> My question is, if I change the DBCC SHRINKFILE statment the following and
> try to run it:
>
>     DBCC SHRINKFILE (N'DB Name_Data' , 1)
>
> What will the results be?  Will it fail and give errors?  Will it shrink the
> file to the smallest possible size (260 MB)?  Will it try to shrink the file
> to 1 MB thus losing/corrupting my data?
>
> Thanks for any help anyone can provide,
>
> Conan Kelly
>
>
>
>
Author
29 Nov 2007 7:17 PM
Conan Kelly
Ben,

Thanks for the info,

Conan




Show quote
"Ben Nevarez" <BenNeva***@discussions.microsoft.com> wrote in message
news:83100FB9-FA39-434B-92D3-4684580FD391@microsoft.com...
>
> It will try to shrink the file to the smallest size possible (it is not
> even
> guaranteed that will shrink the size to 260 MB).
>
> But you are not going to receive errors or lost or corrupt any data.
>
> Hope this helps,
>
> Ben Nevarez
> Senior Database Administrator
> AIG SunAmerica
>
>
>
> "Conan Kelly" wrote:
>
>> Hello all,
>>
>> SSMS>Object Explorer>right-click a DB>Tasks>Shrink>Files
>>     File Type:.....Data
>>     Click "Reorganize pages before...." optioni
>>     Shrink file to:........1 MB
>>
>> As soon as I tab out of the "Shrink file to:" text box, it automattically
>> adjusts to the smallest possible size the data file can be shrunk to (260
>> MB
>> in this case).
>>
>> Then when I "Script Action to New Query Window", I get the following
>> script:
>>
>>     USE [DB Name]
>>     GO
>>     DBCC SHRINKFILE (N'DB Name_Data' , 260)
>>     GO
>>
>> My question is, if I change the DBCC SHRINKFILE statment the following
>> and
>> try to run it:
>>
>>     DBCC SHRINKFILE (N'DB Name_Data' , 1)
>>
>> What will the results be?  Will it fail and give errors?  Will it shrink
>> the
>> file to the smallest possible size (260 MB)?  Will it try to shrink the
>> file
>> to 1 MB thus losing/corrupting my data?
>>
>> Thanks for any help anyone can provide,
>>
>> Conan Kelly
>>
>>
>>
>>
Author
29 Nov 2007 6:43 PM
Kalen Delaney
Hi Conan

Did you read the documentation about DBCC SHRINKFILE? It says this:

"DBCC SHRINKFILE does not shrink a file past the size needed to store the
data in the file. "

So you will not get any corruption, or lose any data.

However, you should read this:
http://www.karaszi.com/SQLServer/info_dont_shrink.asp

--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com


Show quote
"Conan Kelly" <CTBarbarinNOSPAM@msnNOSPAM.comNOSPAM> wrote in message
news:dvD3j.172691$kj1.41899@bgtnsc04-news.ops.worldnet.att.net...
> Hello all,
>
> SSMS>Object Explorer>right-click a DB>Tasks>Shrink>Files
>    File Type:.....Data
>    Click "Reorganize pages before...." optioni
>    Shrink file to:........1 MB
>
> As soon as I tab out of the "Shrink file to:" text box, it automattically
> adjusts to the smallest possible size the data file can be shrunk to (260
> MB
> in this case).
>
> Then when I "Script Action to New Query Window", I get the following
> script:
>
>    USE [DB Name]
>    GO
>    DBCC SHRINKFILE (N'DB Name_Data' , 260)
>    GO
>
> My question is, if I change the DBCC SHRINKFILE statment the following and
> try to run it:
>
>    DBCC SHRINKFILE (N'DB Name_Data' , 1)
>
> What will the results be?  Will it fail and give errors?  Will it shrink
> the
> file to the smallest possible size (260 MB)?  Will it try to shrink the
> file
> to 1 MB thus losing/corrupting my data?
>
> Thanks for any help anyone can provide,
>
> Conan Kelly
>
>
>
Author
29 Nov 2007 7:17 PM
Conan Kelly
Kalen,

Thanks for the info,

Conan


Show quote
"Kalen Delaney" <replies@public_newsgroups.com> wrote in message
news:Ovn7LfrMIHA.5160@TK2MSFTNGP05.phx.gbl...
> Hi Conan
>
> Did you read the documentation about DBCC SHRINKFILE? It says this:
>
> "DBCC SHRINKFILE does not shrink a file past the size needed to store the
> data in the file. "
>
> So you will not get any corruption, or lose any data.
>
> However, you should read this:
> http://www.karaszi.com/SQLServer/info_dont_shrink.asp
>
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.InsideSQLServer.com
> http://sqlblog.com
>
>
> "Conan Kelly" <CTBarbarinNOSPAM@msnNOSPAM.comNOSPAM> wrote in message
> news:dvD3j.172691$kj1.41899@bgtnsc04-news.ops.worldnet.att.net...
>> Hello all,
>>
>> SSMS>Object Explorer>right-click a DB>Tasks>Shrink>Files
>>    File Type:.....Data
>>    Click "Reorganize pages before...." optioni
>>    Shrink file to:........1 MB
>>
>> As soon as I tab out of the "Shrink file to:" text box, it automattically
>> adjusts to the smallest possible size the data file can be shrunk to (260
>> MB
>> in this case).
>>
>> Then when I "Script Action to New Query Window", I get the following
>> script:
>>
>>    USE [DB Name]
>>    GO
>>    DBCC SHRINKFILE (N'DB Name_Data' , 260)
>>    GO
>>
>> My question is, if I change the DBCC SHRINKFILE statment the following
>> and
>> try to run it:
>>
>>    DBCC SHRINKFILE (N'DB Name_Data' , 1)
>>
>> What will the results be?  Will it fail and give errors?  Will it shrink
>> the
>> file to the smallest possible size (260 MB)?  Will it try to shrink the
>> file
>> to 1 MB thus losing/corrupting my data?
>>
>> Thanks for any help anyone can provide,
>>
>> Conan Kelly
>>
>>
>>
>
>

AddThis Social Bookmark Button