Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

space check Expand / Collapse
Author
Message
Posted Saturday, March 22, 2008 7:07 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Sunday, January 29, 2012 1:45 AM
Points: 710, Visits: 1,284
Comments posted to this topic are about the item space check

..>>..

MobashA
Post #473203
Posted Saturday, March 22, 2008 8:29 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, January 21, 2014 9:38 PM
Points: 144, Visits: 447
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





Post #473215
Posted Saturday, March 22, 2008 10:14 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:12 PM
Points: 36,750, Visits: 31,198
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #473234
Posted Monday, May 5, 2008 3:43 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 12, 2012 3:38 PM
Points: 13, Visits: 110
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.
Post #495320
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse