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

132 Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

Numerous problems:

  • The procedure you want is sp_msforeachdb
  • That procedure takes parameter @command1
  • There is no @user_only parameter.

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