space check

  • Comments posted to this topic are about the item space check

    ..>>..

    MobashA

  • There is no need to include upper() in the where clause. TSQL is not case sensitive. Since the minumum allowable amount of space may vary between systems it makes more sense to me to have parameters for the allowable space by drive than to hardcode them. The original script was overly generous in declaring space for its variables. One example, since @convertedC is being set to convert(varchar(20),@c) then @convertedC does not need to be any bigger than 20. And @string would never get any near as long as 8000 characters.

    Revised code:

    alter procedure harddisk_check_space

    @MinOkC int = 20,

    @MinOkNotC int = 3

    as

    begin

    declare @mytable table (drive varchar(10),sp int)

    declare @C int

    declare @notc int

    insert into @mytable exec master.dbo.xp_fixeddrives

    select @C=sp from @mytable

    where drive='C'

    select @notc=sum(sp) from @mytable

    where drive<>'C'

    set @C=@c/1000

    set @notc=@notc/1000

    if(@c < @MinOkC or @notc < @MinOkNotC)

    begin

    declare @string varchar(120)

    declare @convertedC varchar(20)

    declare @convertedNotC varchar(20)

    set @convertedC=convert(varchar(20),@c)

    set @convertedNotC=convert(varchar(20),@notc)

    set @string='there is not enough space left on the server, '+@convertedC+' GB left on C: and '+@convertedNotC+' GB left on the other drives'

    raiserror(@string,16,1) with log

    -- print (@string)

    end

    end

  • ksullivan (3/22/2008)


    There is no need to include upper() in the where clause. TSQL is not case sensitive.

    Not quite true... the default is to setup SQL Server so that it is neither Case nor Accent Sensitive. However, I've seen many servers that have been setup to be Case Sensitive. If you're trying to make code work in any Case Sensitive environment, the use of UPPER or LOWER is prudent.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Maybe it's trivial, but shouldn't the divisor to convert MB to GB be 1024? Otherwise, the free space calculated is more than what is truly available.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply