October 9, 2008 at 7:32 am
What is command to run find data and log files for databases. Thank you
October 9, 2008 at 7:39 am
I understand your question is to find the database and log files.
You can try this:
use [database_name]
select * from sys.database_files
October 9, 2008 at 8:32 am
Thank you, Is there way to run the same think but for all database?
October 9, 2008 at 9:03 am
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
October 9, 2008 at 9:58 am
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