Simple script to show what drives all databases are on

, 2005-12-09

Had a need for this the other day. We just needed a quick dump of which

drives each database was using. Don't know if it's good enough to make

the useful script category for SSC as I wrote it on the fly (so use at your own risk), but here it is:

DECLARE @database_name sysname

DECLARE @SQL nvarchar(4000)

DECLARE cursDatabases CURSOR FAST_FORWARD

FOR

SELECT name FROM sysdatabases

OPEN cursDatabases

CREATE TABLE #DatabaseDiskUsage

(DatabaseName sysname, DriveLetter char(1))

FETCH FROM cursDatabases INTO @database_name

WHILE (@@FETCH_STATUS = 0)

BEGIN

  SET @SQL = N'INSERT INTO #DatabaseDiskUsage (DatabaseName, DriveLetter)

              

SELECT DISTINCT ''' + @database_name + ''',

              

UPPER(LEFT(filename, 1)) FROM ' + @database_name + '..sysfiles'

  EXEC sp_executesql @SQL

  FETCH NEXT FROM cursDatabases INTO @database_name

END

CLOSE cursDatabases

DEALLOCATE cursDatabases

SELECT DatabaseName, DriveLetter FROM #DatabaseDiskUsage

DROP TABLE #DatabaseDiskUsage

Rate

Share

Share

Rate

Related content

Database Mirroring FAQ: Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup?

Question: Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup? This question was sent to me via email. My reply follows. Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup? Databases to be mirrored are currently running on 2005 SQL instances but will be upgraded to 2008 SQL in the near future.

2009-02-23

1,567 reads

Networking - Part 4

You may want to read Part 1 , Part 2 , and Part 3 before continuing. This time around I'd like to talk about social networking. We'll start with social networking. Facebook, MySpace, and Twitter are all good examples of using technology to let...

2009-02-17

1,530 reads

Speaking at Community Events - More Thoughts

Last week I posted Speaking at Community Events - Time to Raise the Bar?, a first cut at talking about to what degree we should require experience for speakers at events like SQLSaturday as well as when it might be appropriate to add additional focus/limitations on the presentations that are accepted. I've got a few more thoughts on the topic this week, and I look forward to your comments.

2009-02-13

360 reads