BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 Subscribe!

Thursday, November 20, 2008
SQL: Where are the database files?

From within the SQL Server Management Studio you can right click on a database and view its properties to get a list of the physical files that make up a database. If you do not have access to SQL Management Studio and the database is online you can run the sp_helpfile stored procedure. The sp_helpfile stored procedure lists the files for the current (individual) database; the database must be online. What about retrieving file information for offline databases?
Another alternative for retrieving the list of database files for a single or collective set of databases is to query the sys.master_files table. You can query the sys.master_files database if the database is online, offline or in one of the other states. The following query retrieves database file information:
1SELECT
2 database_id,
3 DB_Name(database_id) as database_name,
4 [file_id],
5 type_desc,
6 [name],
7 physical_name,
8 state_desc,
9 [size],
10 max_size
11FROM
12 sys.master_files
13WHERE
14 -- you can use the DB_ID function to return the
15 -- database id of a database by name
16 (database_id = DB_ID(N'master'))
17 -- if you know the id you can filter by it directly
18 -- (database_id = 1)
19ORDER BY
20 type_desc DESC,
21 physical_name;




The sys.databases table has information about the database in the current SQL Server instance.

1SELECT
2 database_id,
3 [name],
4 compatibility_level,
5 collation_name,
6 state_desc
7FROM
8 sys.databases;


Labels: ,

posted by Brad Prendergast at 9:08:00 PM
Comments:
Links to this post:

Create a Link

Recent Posts
 Show Desktop in my QuickLaunch Toolbar?
 Command Line: Visual Source Safe
 SQL: Remove / Delete Orphan Users
 SQL Delete/Drop a User from each Database
 Is there an 'I' in phone?
 SQL Optimization: Am I missing any indexes? - Part...
 Meaningful Signature File Quotes
 My Shared RSS Items
 Edit those XML files
 A little System.Diagnostics

 Subscribe!


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger