m@rc-lenzin

Wenn etwas schief geht, dann freu dich. Das sind die Geschichten die dir in Erinnerung bleiben werden

MSSQL – Create Check Database-Size Mail

use msdb
go
exec sp_send_dbmail
	@profile_name='DefaultMail',
	@recipients='your@email.ch',
	@subject='Database Size',
	@body='Database Size',
	@query='
set nocount on
go	
select	x.name,
		x.LOG_SIZE_MB,
		x.LOG_MAXSIZE_MB,
		x.DATA_SIZE_MB,
		x.DATA_MAXSIZE_MB,
		case when x.DATA_MAXSIZE_MB = 0 then ''open''
			else cast(ceiling(100 / cast(x.DATA_MAXSIZE_MB as numeric)*CAST(x.DATA_SIZE_MB as numeric)) as varchar(3))+''%''
			end as PCT_FULL
from	(	select	cast(c.name as varchar(20)) as name,
					(8192 * sum(cast(a.size as bigint)))    / 1024 / 1024 as LOG_SIZE_MB,
					(8192 * sum(cast(a.maxsize as bigint))) / 1024 / 1024 as LOG_MAXSIZE_MB,
					(8192 * sum(cast(b.size as bigint)))    / 1024 / 1024 as DATA_SIZE_MB,
					(8192 * sum(cast(b.maxsize as bigint))) / 1024 / 1024 as DATA_MAXSIZE_MB
			from	sys.sysaltfiles a,
					sys.sysaltfiles b,
					sys.databases c
			where	c.database_id  = a.dbid
			and	c.database_id  = b.dbid
			--and	c.database_id > 4
			and	lower(a.name) like ''%log%''
			and	lower(b.name) not like ''%log%''
			group	by c.name) x
order	by case when x.DATA_MAXSIZE_MB = 0 then ''0''
			else ceiling(100 / cast(x.DATA_MAXSIZE_MB as numeric)*CAST(x.DATA_SIZE_MB as numeric))
			end desc
go'

 

Weiter Beitrag

Zurück Beitrag

© 2025 m@rc-lenzin

Thema von Anders Norén