Datafile Growth in SQL Server - Getting the Statistics Part II
Date: 03/11/11
(SQL Server) Keywords: sql
In our last entry we talked about getting datafile usage in SQL Server. Today, we'll implement sp_file_space in another stored procedure that combines it with the extended stored procedure xp_fideddrives to calculate the free space and stores the data in two standard tables.
CREATE PROCEDURE [dbo].[sp_log_spaceused]
as
create table #freespace
(
drive char(1) null,
MBfreespace bigint null
)
set nocount on
delete from #freespace
-- log this servers current space used
insert into file_space_log exec.master.dbo.sp_file_space
-- log the freespace
insert into #freespace
(
drive,
MBfreespace
)
exec master.dbo.xp_fixeddrives
-- server_drive_space insert
insert into free_space_log
select
drive,
MBfreespace
from #freespace
GO
** Please be responsible with free code. Test and check before implementing in a production environment
Source: https://sqlserver.livejournal.com/73862.html