|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: 2 days ago @ 4:07 AM
Points: 180,
Visits: 516
|
|
Hi I use the below script to find out the space consumed by a particular DB. It works fine for me.
select A.[Size]/128 AS [FileSize] ,FileProperty (A.[name], 'spaceused') / 128 AS [Consumed] ,A.[max_size]/128 AS [MaxSize] ,A.growth/128 AS [AutoGrowMB] ,CONVERT(VARCHAR(25), A.[Name]) AS [LocicalName] ,A.[physical_name] AS [FileLocation] from sys.master_files A where A.database_id = DB_ID(DB_NAME()) order by A.type, a.[file_id]
But then when I do sp_Helpdb <DB Name> I see different numbers on the column SIZE. Can the Consumed size be less than the Initial Size of the file???
Please lighten me with your knowledge
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Yesterday @ 9:25 AM
Points: 81,
Visits: 864
|
|
Check this query:
select df.name AS LogicalFileName , isnull(fg.name, 'Log') AS FilegroupName , df.physical_name AS PhysicalOSName , (df.size * 8 / 1024) AS SizeMBs , (fileproperty(df.name, 'SpaceUsed') / 128) AS SpaceUsedMBs , (df.size * 8 / 1024) - (fileproperty(df.name, 'SpaceUsed') / 128) AS FreeMBs , case df.max_size when 0 then 'No Growth' when -1 then 'Unlimited' when 268435456 then '2TB' else cast(df.max_size / 128 AS VARCHAR(10)) + ' MBs' end AS MaxFileSize , case df.is_percent_growth when 0 then cast(df.growth / 128 AS VARCHAR(10)) + ' MBs' else CAST(df.growth AS VARCHAR(10)) + ' %' end AS Growth ,cast(cast((fileproperty(df.name, 'SpaceUsed') / 128) as numeric(20,2)) / cast(df.size / 128 as numeric(20,2)) * 100 as numeric(20,2)) as PercentUsed from sys.database_files df left outer join sys.filegroups fg ON df.data_space_id = fg.data_space_id order by df.type
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: 2 days ago @ 4:07 AM
Points: 180,
Visits: 516
|
|
Thanks mahesh.. your query is a little more elaborative than mine.
But my main question is if the Initial size is 70 GB can the consumed be 3 mb? I have seen this case happening with Tempdb last week.
First I used select A.[Size]/128 AS [FileSize] ,FileProperty (A.[name], 'spaceused') / 128 AS [Consumed] ,A.[max_size]/128 AS [MaxSize] ,A.growth/128 AS [AutoGrowMB] ,CONVERT(VARCHAR(25), A.[Name]) AS [LocicalName] ,A.[physical_name] AS [FileLocation] from sys.master_files A where A.database_id = DB_ID(DB_NAME()) order by A.type, a.[file_id]
then i see that in sp_helpdb <DB NAme> is giving different numbers for the column 'Size'
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Today @ 2:10 AM
Points: 578,
Visits: 1,107
|
|
But my main question is if the Initial size is 70 GB can the consumed be 3 mb? I have seen this case happening with Tempdb last week.
You can set a database with an intial size. This is preferred if you have an estimated size your database needs to be than to having a very small data file that has to issue a lot of growth events which can lead to bad fragmentation. The space that is not used is white space in the file that is reserved for future use.
TempDB get objects created and dropped all the time depending on the operations that are going on with different databases. The thing you want to watch out for is to ensure that TempDB does not fill up where it cannot grow if necessary.
Joie Andrew "Since 1982"
|
|
|
|