Wednesday, March 7, 2012

Schedule mail of DB sizes

Wonder if anyone can help me out here.

I'm trying to set up a job to run overnight that mails me the size of all the databases on SQL Server.

The way I'm getting the size of the db's is by running the following in SQL Query Analyzer...

EXEC sp_MSforeachdb @.command1="print '?' select cast(name as varchar(32)), round(size * 8 / 1.024,3) from ?..sysfiles"

Can anyone suggest a way that I can export the results of this to a text file that can then be mailed to me as part of a scheduled job.

Or can anyone suggest a better/easier way of doing this??

Thanks in advance. :)exec master..xp_sendmail @.recipients = 'recipients '
,@.message = 'message'
,@.query = select cast(name as varchar(128)) "LogicalFileName", (size * 8 / 1024) "Size in MB" from master..sysaltfiles'|||... I'm afraid I've not explained myself properly :(

SQL Mail is not set up on this server, so I need a file creating which I can then ftp to a location from which it can be mailed.

And I'm afraid it's not as simple as setting up SQL Mail, it has to be sent from a different box.

Any suggestions?

Thanks|||Look into isql or osql to execute the query and store results in a file|||Create an DTS package, two data sources, one as your SQL Serv db, one as "Output Text", then create a "transfer" task between the SQL serv and the text file. Edit the transfer task and set the source as "execute sql" and than select the "exec ... " string you are using now.

Then schedule your DTS package as you like it...|||no need for dts here .. simple osql or isql will do the task.|||Thanks Enigma.

Just looking into osql now and that seems to do the trick.

No comments:

Post a Comment