sqlschool.gr logo

articles

Articles of SQLschool.gr Team

sp_EstimateAllDBBackupSize - V 1.01

Antonios Chatzipavlis
Tuesday 22 September 2015

Νέα έκδοση της sp_EstimateAllDBBackupSize που διορθώνει τα errors που αφορούσαν τα overflows και offline databases

use master
go

if not exists (select * from information_schema.routines where routine_name = 'sp_EstimateAllDBBackupSize')
    exec ('create proc dbo.sp_EstimateAllDBBackupSize as select ''stub version, to be replaced''')
go



alter proc sp_EstimateAllDBBackupSize
as
/*********************************************************************************************
sp_EstimateAllDBBackupSize (c) 2015 SQLschool.gr - Antonios Chatzipavlis

Version History
1.00    Sep 19, 2015
1.01    Sep 22, 2015 fix the overflow and offline databases errors

Feedback: info@sqlschool.gr

License: 
    sp_EstimateAllDBBackupSize is free to download and use for personal, educational, 
    and internal corporate purposes, provided that this header is preserved. 
*********************************************************************************************/
begin
    set nocount on;

    declare @dbname sysname;
    declare @query nvarchar(1000);
    declare @stm nvarchar(1000);

    set @query = 'use ?
    insert into #backupsize
    select      db_name() 
            , convert(decimal(15,2), sum(size) * 8192.0 / 1048576.0) 
            , convert(decimal(15,2), sum(fileproperty(name,''spaceused'')) * 8192.0 / 1048576.0) 
    from sys.database_files;'

    if ( object_id('tempdb..#backupsize') is not null )
    begin
        drop table #backupsize;
    end    

    create table  #backupsize
    (
        database_name sysname
    ,    total_db_size_mb decimal(15, 2)
    ,    estimated_backup_size_mb decimal(15, 2)
    );
    
    declare dblist cursor local fast_forward for 
            select name from sys.databases 
            where state=0 
            order by name;

    open dblist;

    fetch next from dblist into @dbname;
    while (@@fetch_status <> -1)
    begin
        if (@@fetch_status <> -2)
        begin
            set @stm =replace(@query,'?',QUOTENAME(@dbname));
            execute(@stm);
        end
        fetch next from dblist into @dbname;
    end

    close dblist;
    deallocate dblist;

    select * from #backupsize;
end
go

Antonios Chatzipavlis

Antonios Chatzipavlis

Antonios Chatzipavlis is a highly experienced Data Solutions Consultant and Trainer. He has been working in the IT industry since 1988, holding various roles such as senior developer, IT Manager, Data & AI Solutions Architect and Consultant.

Since 1995, Antonios has focused on modern technologies and software development tools, primarily by Microsoft. He has specialized in Data & AI since 2000, with expertise in Microsoft Data Platform (SQL Server, Azure SQL Databases, Azure Synapse Analytics, Microsoft Fabric, Power BI, AI) and Databricks.

Antonios is also a Microsoft Certified Trainer (MCT) for over 25 years, has been recognized as a Microsoft Most Valuable Professional (MVP) in Data Platform since 2010 and he is in the Data Expert 40 Powerlist 2024 by Boussias. He is the co-founder and visionary behind XLYTiCA, a company dedicated to Data & AI solutions.

Episode

Task Flows in Microsoft Fabric

image

More Episodes...

Tip

Get Certified: Become a Fabric Data Engineer

More Tips...

Become a member

If you want to receive updates from us become a member to our community.

Connect

Explore

Learn


sqlschool.gr © 2010-2025 All rights reserved

This site uses cookies for operational and analytics purposes only. By continuing to browse this site, you agree to their use.