sqlsql-serversp-msforeachdb

i want to store size of the log file in a temp table


what is the wrong with

insert into #tempA(MailSize) EXEC sp_foreachdb_dev @command = N' USE ? SELECT (size * 8)/1024.0 AS size_in_mb FROM
sys.database_files WHERE
data_space_id = 0', @user_only = '1' select * from #tempA

i want to store size of the log file in a temp table


Solution

  • Numerous problems:

    The version below works:

    create table #tempA (
        MailSize decimal
    )
    
    insert into #tempA(MailSize) 
        EXEC sp_msforeachdb 
            @command1 = N' USE ? 
                           SELECT (size * 8)/1024.0 AS size_in_mb 
                           FROM sys.database_files 
                           WHERE data_space_id = 0'
    
    select * from #tempA
    
    drop table #tempA