SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


space check


space check

Author
Message
mobasha
mobasha
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2470 Visits: 1284
Comments posted to this topic are about the item space check

..>>..

MobashA
ksullivan
ksullivan
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1024 Visits: 450
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






Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (382K reputation)SSC Guru (382K reputation)SSC Guru (382K reputation)SSC Guru (382K reputation)SSC Guru (382K reputation)SSC Guru (382K reputation)SSC Guru (382K reputation)SSC Guru (382K reputation)

Group: General Forum Members
Points: 382893 Visits: 43046
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Michael Sallmen
Michael Sallmen
Valued Member
Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)

Group: General Forum Members
Points: 65 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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search