SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query to know free space available servers
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vinay_555
Starting Member

India
10 Posts

Posted - 07/29/2013 :  09:55:08  Show Profile  Reply with Quote
Hi,

I would like to Know the sql queries related to the servers spaces available.



MuMu88
Aged Yak Warrior

547 Posts

Posted - 07/29/2013 :  10:14:28  Show Profile  Reply with Quote

SP_SPACEUSED


Or code from following site:
http://stackoverflow.com/questions/866139/best-way-to-find-free-space-in-sql-server-databases

select
      name
    , filename
    , convert(decimal(12,2),round(a.size/128.000,2)) as FileSizeMB
    , convert(decimal(12,2),round(fileproperty(a.name,'SpaceUsed')/128.000,2)) as SpaceUsedMB
    , convert(decimal(12,2),round((a.size-fileproperty(a.name,'SpaceUsed'))/128.000,2)) as FreeSpaceMB
from dbo.sysfiles a


Go to Top of Page

vinay_555
Starting Member

India
10 Posts

Posted - 07/29/2013 :  10:54:55  Show Profile  Reply with Quote
Thanks for your valuable reply...

But I need queries to know disk space availabilities (free spaces in disks) on remote servers but not database space availability.

Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 07/29/2013 :  10:55:20  Show Profile  Reply with Quote
Yet another way:
SELECT * FROM sys.dm_os_performance_counters 
WHERE counter_name = 'Data File(s) Size (KB)'
OR counter_name = 'Log File(s) Size (KB)'                                                                                                    '
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 07/29/2013 :  10:59:56  Show Profile  Reply with Quote
quote:
Originally posted by vinay_555

Thanks for your valuable reply...

But I need queries to know disk space availabilities (free spaces in disks) on remote servers but not database space availability.



All the OS related DMVs are listed here http://msdn.microsoft.com/en-us/library/ms176083.aspx I don't see one that directly lists the disks mounted on the server. The closest may be sys.dm_os_volume_stats which would give you info for the volume on which the specific file resides.

You may be better off looking up Powershell scripts that can crawl through lists of servers and return info on disk space availability and all othe kinds of things.

Edited by - James K on 07/29/2013 11:00:52
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000