|
|
|
Say 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
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, May 28, 2013 7:12 PM
Points: 144,
Visits: 445
|
|
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
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 11:35 PM
Points: 33,107,
Visits: 27,029
|
|
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."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
Grasshopper
      
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.
|
|
|
|