Results 1 to 11 of 11

Thread: Dumb question

  1. #1
    Join Date
    Jul 2004
    Location
    bay area
    Posts
    61

    Dumb question

    Hi all,
    I have a question. I have a database which is really big. I got into the enterprise manager and right click on the database and select property, I saw the
    the size:7000MB and space available is 6700MB. Does that mean when the database initially created, it allocated the storage space is around 7GB and now even I delete some data in the database, it will not shrink the database size, it only makes the available space bigger? Is there any way I shrink the database size without destroy any data?

    Thanks!
    Betty

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You are right. However 7GB includes both data and log files. To shrink database you have to run

    dbcc shrinkdb
    or
    dbcc shrinkfile

  3. #3
    Join Date
    Jul 2004
    Location
    bay area
    Posts
    61
    I can also change in the enterprise manager directly right, there is data file which has

    Filename, location , allocated space etc. I just need to change the allocated space to,say, from 6GB 4 GB, is that OK.
    Thank you so much for your quick response.

    Betty

  4. #4
    Join Date
    Jul 2004
    Location
    bay area
    Posts
    61
    I exec the following command:

    DBCC SHRINKDATABASE (TestDatbase, 50)
    I got the following message:
    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

    It seems successful, but when I open another enterprise manager, the data file size is still the same, what's going on?

    Betty

  5. #5
    Join Date
    Feb 2003
    Posts
    1,048
    Create a backup first to create a checkpoint.

    Also, for future ease, you may want to consider enabling the autoshrink property on the database. Right click on the database, click Properties, select the Options tab, select autoshrink, click Okay.

  6. #6
    Join Date
    Sep 2002
    Posts
    5,938
    If the db is in full or bulk-logged recovery model, you have to do log backup periodically to truncate committed transactions from log.

  7. #7
    Join Date
    Jul 2004
    Location
    bay area
    Posts
    61
    Hi, all
    I just found this information in SQL analyzer(search for "shrinking a database")
    ------------
    You cannot shrink an entire database to be smaller than its original size. Therefore, if a database was created with a size of 10 megabytes (MB) and grew to 100 MB, the smallest the database could be shrunk to, assuming all the data in the database has been deleted, is 10 MB.
    ------------

    Does that mean you cannot shrink a database to a size smaller than the initially allocated size if later on you notice that database doesn't need such a large allocation? then what you can do?

    Thanks!

    Betty

  8. #8
    Join Date
    Sep 2002
    Posts
    5,938
    Yes, it's in sql books online. But I tried shrink file to size smaller than initial size in enterprise manager and seemed to work.

  9. #9
    Join Date
    Feb 2003
    Posts
    1,048
    On the same page in BOL:

    To shrink a file to a size smaller than its minimum size, use DBCC SHRINKFILE and specify the new size. Executing DBCC SHRINKFILE changes the minimum file size to the new size specified.

  10. #10
    Join Date
    Jul 2004
    Location
    bay area
    Posts
    61
    I issued the command

    DBCC shrinkfile(XXX, 4)
    I meant 4GB, but actually the unit in command is 4MB. Now I looked at it in the enterprise manager. It says: space allocated is 1.3GB and space available is 700MB. that means I didn't lose any data, right?

    Betty

  11. #11
    Join Date
    Feb 2003
    Posts
    1,048
    Right. DBCC shrinkfile will never truncate data, only space. It attempts to shrink to the value you give it, but will only go as far as it can.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •