Log Files/Data files

  • What is command to run find data and log files for databases. Thank you

  • I understand your question is to find the database and log files.

    You can try this:

    use [database_name]

    select * from sys.database_files

  • Thank you, Is there way to run the same think but for all database?

  • There might be a better way of writing this query... But you can use this one and maybe modify this further..

    declare @dbname table (dbid int,db varchar(300))

    --the insert statement inserts below the names of all the databases into the table variable

    insert @dbname

    select database_id,name from sys.databases

    declare @sql varchar(350)

    declare @count int

    declare @dbid int

    declare @db varchar(300)

    set @count=(select count(dbid) from @dbname) --counter for databases

    set @dbid=(select top 1 dbid from @dbname) --variable to store dbid temporarily

    set @db=(select db from @dbname where dbid=@dbid) --variable to store database name temporarily

    --select * from @dbname

    while (@count>0)

    begin

    select @db

    EXEC ('use['+@db+']; SELECT * from sys.database_files')

    set @count=@count-1 --decrement count for the database0

    set @dbid=(select top 1 dbid from @dbname where dbid>@dbid order by dbid) --assign new dbid

    set @db=(select db from @dbname where dbid=@dbid) --assign new database name

    End

  • Thank you so much

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply