|
-
Jan 23rd, 2009, 02:13 PM
#1
-
Jan 23rd, 2009, 02:57 PM
#2
Re: Shrink DB (SQL Server 2005)
You can truncate the log files too if they are no use to you. They too take a lot of space.
I think your missing 30 Gig is in log files. Have you checked the log file size? 
e.g.
Dbcc shrinkfile('templog')
-
Jan 23rd, 2009, 03:01 PM
#3
Re: Shrink DB (SQL Server 2005)
No in the log..... Already di that. I'm looking at the data file size.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jan 23rd, 2009, 04:28 PM
#4
Re: Shrink DB (SQL Server 2005)
ShrinkDatabase will not shrink a database file less than its minimum size. The minimum size is set by Create Database or Alter Database Modify File statements. Also, I think the Database option "Automatically Grow File" changes/sets the minimum size as well.
The returned result set of ShrinkDatabase should help in determining how large of a file is required.
You might want to try DBCC ShrinkFile instead.
Last edited by brucevde; Jan 23rd, 2009 at 04:32 PM.
-
Jan 23rd, 2009, 09:20 PM
#5
Re: Shrink DB (SQL Server 2005)
Bruce
I'm already doing that (I'll post the code I'm using later on my home system now). The bigger question I'm trying to answer is the issue of the free space. When I drop the column from the table there is now difference in the amount of free space in the database. Is it because the rows are still spread around the datapages? Would I need to re-orginize the table to get the space back?
I hope I'm making sense.... Do I still have rows spread accros multiple datapages because they were spread due to the size of the data in that column I'm droping. It was a created as an Image datatype. In the database that this information is moving to after useing ShrinkFile I get the datafile size down to 34 gig from 57 gig. I can't get the same reducion on the orginial database.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jan 24th, 2009, 06:56 AM
#6
Re: Shrink DB (SQL Server 2005)
Back on work machine this the the script I'm using for shrink:
sql Code:
DECLARE @DataFileFreeSpaceGB INT
DECLARE @LogFileFreeSpaceGB INT
SELECT @DataFileFreeSpaceGB = 10
SELECT @LogFileFreeSpaceGB = 1
DECLARE @DBName VARCHAR(100) --Database Name
DECLARE @filenameD VARCHAR(500) -- DataFile
DECLARE @filenameL VARCHAR(500) -- Logfile
DECLARE @DSpaceUsed DECIMAL(10) --Spaceused in Meg
DECLARE @LSpaceUsed DECIMAL(10) --Spaceused in Meng
DECLARE @sStr VARCHAR(200) -- A string SQL statement to EXECute
SELECT @DBName = DB_NAME()
SET @sStr = 'ALTER DATABASE ' + @DBName + ' SET RECOVERY Simple'
EXEC (@sStr)
--DataFile
SELECT @fileNameD = name From sys.database_files Where type = 0
SELECT @DSpaceUsed = (FILEPROPERTY (@filenameD,'SpaceUsed ') * 8192.0)/1024/1024
SET @DSpaceUsed = @DSpaceUsed + (@DataFileFreeSpaceGB * 1000)
SET @sStr = 'DBCC ShrinkFile (' + @fileNameD + ',' + Convert(VARCHAR(50),@DSpaceUsed) + ')'
EXEC (@sStr)
--Logfile
SELECT @fileNameL = name From sys.database_files Where type = 1
SELECT @LSpaceUsed = (FILEPROPERTY (@filenameL,'SpaceUsed ') * 8192.0)/1024/1024
SET @LSpaceUsed = @LSpaceUsed + (@LogFileFreeSpaceGB * 1000)
SET @sStr = 'DBCC ShrinkFile (' + @fileNameL + ',' + Convert(VARCHAR(50),@LSpaceUsed) + ')'
EXEC (@sStr)
SET @sStr = 'ALTER DATABASE ' + @DBName + ' SET RECOVERY FULL'
EXEC (@sStr)
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jan 27th, 2009, 08:25 AM
#7
Re: Shrink DB (SQL Server 2005)
Found the answer in Books On-Line. I need to Rebuild the Primary Key index. Once I did that I was able to use the script above to reclaim the space.
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|