December 11, 2007 at 9:54 am
Hi everyone,
I need to provide the directory paths for all my database .mdf, ndf, and .log files. to an IT staff person. I could right click each data base, select files and provide the path information. Is there an information_Schema, Catalog and/or MetaData View that will provide a table of paths, preferably within each instance, for both 2K and ’05 versions? Thanks for everyone for being there to help.
SQL 2K and ’05 standard
Ed
December 11, 2007 at 10:08 am
This works on 7.0, 2000, and 2005
Get Server Database File Information
December 11, 2007 at 10:27 am
Well, since it needs to work for 2005 as well as 2000 you can't use the DMVs or DMFs. This will do the trick however:
EXEC sp_MSForEachDB
'SELECT CONVERT(char(100), SERVERPROPERTY(''Servername'')) AS Server,
''?'' as DatabaseName,
[?]..sysfiles.name,
[?]..sysfiles.filename
From [?]..sysfiles'
You can tap into more metadata from the system tables as well if you need to using this method. Slap my hands for using the system tables, but it works!
- Tim Ford, SQL Server MVPhttp://www.sqlcruise.comhttp://www.thesqlagentman.com http://www.linkedin.com/in/timothyford
December 11, 2007 at 12:21 pm
Fantastic! You guys are the best. The results are exactly what is needed. Its there a way to place the results so it can be grabbed
by DTS or SSIS to send to a flat fole.
December 11, 2007 at 12:32 pm
Something like this will place everything into a single result set. Just drop the temp table #Results when done.
CREATE TABLE #Results (SERVER VARCHAR(100), DatabaseName VARCHAR(100), NAME VARCHAR(100), filename VARCHAR(200))
EXEC sp_MSForEachDB
'INSERT INTO #Results(Server, DatabaseName, Name, filename)
SELECT CONVERT(char(100), SERVERPROPERTY(''Servername'')) AS Server,
''?'' as DatabaseName,
[?]..sysfiles.name,
[?]..sysfiles.filename
From [?]..sysfiles'
SELECT * FROM #Results ORDER BY SERVER, DatabaseName, NAME
- Tim Ford, SQL Server MVPhttp://www.sqlcruise.comhttp://www.thesqlagentman.com http://www.linkedin.com/in/timothyford
December 11, 2007 at 12:55 pm
I'd use two different versions of the script, one for each SQL Server version, especially as the 2000 one might not work in 2008. Just return the same values so your table can hold them, but use a proc or function to get the data in the best way for each version.
December 11, 2007 at 2:23 pm
Anyone ever hear of sp_HelpFile? 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
December 11, 2007 at 2:33 pm
Returns more info than what is asked for and the scope is the current db just as the other approach.
- Tim Ford, SQL Server MVPhttp://www.sqlcruise.comhttp://www.thesqlagentman.com http://www.linkedin.com/in/timothyford
December 11, 2007 at 3:44 pm
Yuh huh... you watch... the next thing the boys from ops will ask for is a summary of the files sizes 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
December 11, 2007 at 4:02 pm
Better than the Analyst I had who wanted to open up a .ldf in notepad to do a search for a string value! That was one for sqldumbass.com let me tell you!
- Tim Ford, SQL Server MVPhttp://www.sqlcruise.comhttp://www.thesqlagentman.com http://www.linkedin.com/in/timothyford
December 11, 2007 at 7:04 pm
Heh... sorry... don't see the connection 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply