datetime century date into pad dynamic cursor money percent sp job isnumeric isdate over update
SQLUSA.com
SQL 2008 GRAND SLAM ON 49 CD
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL Server Training SQL 2005 Scripts SQL 2008 Articles
SQL JOBS News Format Developer
How to monitor the disk drives for low free space?

Execute the following T-SQL example scripts in Microsoft SQL Server Management Studio Query Editor to create a low disk space monitoring stored procedure. The sproc can be scheduled with SQL Server Agent for periodic execution.

-- Create stored procedure to monitor free disk space

USE MASTER;

GO

CREATE PROC sprocMonitorFreeDisk

AS

  BEGIN

    CREATE TABLE #FreeHardDiskSpace (

      ID        INT    IDENTITY ( 1 , 1 ),

      Drive     CHAR(1),

      FreeMB    INT,

      Threshold INT)

    

    INSERT INTO #FreeHardDiskSpace

               (Drive,

                FreeMB)

    EXEC MASTER.dbo.xp_fixeddrives

    

    UPDATE #FreeHardDiskSpace

    SET    Threshold = 1024

    

    UPDATE #FreeHardDiskSpace

    SET    Threshold = 800

    WHERE  Drive = 'C'

    

    UPDATE #FreeHardDiskSpace

    SET    Threshold = 2500

    WHERE  Drive = 'F'

    

    DECLARE  @i         INT,

             @Drives    INT,

             @Drive     CHAR(1),

             @FreeMB    INT,

             @Threshold INT,

             @Parm1     CHAR(50),

             @Parm2     CHAR(50)

    

    SELECT @Drives = count(* )

    FROM   #FreeHardDiskSpace

    

    SET @i = 1

    

    WHILE (@i <= @Drives)

      BEGIN

        SELECT @FreeMB = FreeMB,

               @Threshold = Threshold,

               @Drive = Drive

        FROM   #FreeHardDiskSpace

        WHERE  ID = @i

        

        SET @Parm1 = 'Free Space Alert on ' + @Drive + ' Drive'

        

        SET @Parm2 = 'Free space on ' + @Drive + ' Drive is below ' +

                     convert(VARCHAR,@Threshold) + ' MB'

        

        IF @FreeMB < @Threshold

          EXEC msdb.dbo.sp_send_dbmail

            @recipients = 'dina.smith@abc.com' ,

            @subject = @Parm1 ,

            @body = @Parm2

        

        SET @i = @i + 1

      END

  END

 

GO

 

-- execute stored procedure

EXEC sprocMonitorFreeDisk

 

-- Free disk space check system procedure

EXEC MASTER.dbo.xp_fixeddrives

/*

drive  MB free

C  447248

F  261628

*/

 

------------

 

 

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
Microsoft SQL Server 2012 Training Videos at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Accounting
Administrative
Advertising
Arts
Architecture
Banking
Business Intelligence
Career Jobs
Celebrity
Computer
Consulting
Customer Service
Education
Engineering
Entertainment
Entry Level
Executive
Federal
Finance
Government
Hardware
Healthcare
Hospital
Human Resources
Information Technology
Insurance
Internet
Job Openings
Laboratory
Law Enforcement
Legal
Logistics
Manufacturing
Marketing
Medical
Military
Nursing
Pharmaceutical
Physician
Public Relations
Publishing
Real Estate
Restaurant
Retail
Sales
Social Media
Software
SQL Database
Telecomm
Therapist
Training
Transportation
Truck Driver
Travel
Web
Work from Home

FREE SS SQL / BI OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011 Microsoft Community Contributor 2012

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts

JOIN US ON TWITTER

Copyright 2005-2012, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.