From Cursor into Table

  • Hello everybody,

    I created this cursor in order to find data and log (.mdf and .ldf) files for each database on the server .So far I can see all Data files (.mdf) from master.sysdatabases , but can not find ALL logs in one place like Data files, only inside the each database. So, I created this to see them all at once :

    declare DBName_cursor cursor

    for

    select name from master..sysdatabases

    declare @name varchar (50)

    declare @sql nvarchar(279)

    open DBName_cursor

    fetch next from DBName_cursor into @name

    WHILE @@FETCH_STATUS = 0

    begin

            set @sql = 'use ' + quotename(@name) + '  select name, filename from sysfiles order by fileid' 

    FETCH NEXT FROM DBName_cursor into @name

      

    end

       CLOSE DBName_cursor

       DEALLOCATE DBName_cursor

    Now, I am thinking, is it possible to put everything from that cursor into one table to be able to make search or update or anything else I need with this data.

    Maybe  another Cursor inside this Cursor....? (just guessing...:confused

    Thank you people!

     

     

     

  • i think you can get everything you might want straight from master:

    select  db_name(dbid),name, filename from master.dbo.sysaltfiles order by db_name(dbid)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you! I did not look at that table at all, just checked sp_helpfile and sp_helpdb trying to find where the files name are coming from silly me 

Viewing 3 posts - 1 through 2 (of 2 total)

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