i am trying to shrink database which has a simple recovery model.It has about 10 gb free space but it did not change.
Here is how i get free space and shrink comment
select
a.FILEID,name,
convert(decimal(12,2),round(a.size/128.000,2)) as FILE_SIZE_MB,
convert(decimal(12,2),round(fileproperty(a.name,'SpaceUsed')/128.000,2))as [SPACE_USED_MB],
convert(decimal(12,2),round((a.size-fileproperty(a.name,'SpaceUsed'))/128.000,2))[FREE_SPACE_MB] ,
NAME = left(a.NAME,15),
FILENAME = left(a.FILENAME,30)
from
dbo.sysfiles a
Here is the comment how i shrink file
dbcc shrinkfile(<file_name>,<space_used_mb>)
Actually shrinkfile's 2nd argument is target_space, not 'space_used_mb'. So, the following code should cut your data file, if the db is small enough.
USE master
GO
dbcc shrinkfile( fileId, 250 );
Also, you may consider using SHRINKDATABASE for you case (but be careful about that!)
DBCC SHRINKDATABASE ( [SHRINKED_DB_NAME] )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.