Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

In one of my production databases, I have a filegroup with 3 data files sitting on 3 different disks. There are over 50 tables on this filegroup.

How do I identify the location of each of the 50 tables between the 3 data files? I need to know on which data file does the clustered index for each table reside.

Example :

Table A : Datafile 1 : FG1
Table B : Datafile 2 : FG1
Table C : Datafile 1 : FG1
Table D : Datafile 3 : FG1
share|improve this question
add comment

2 Answers

An object in a filegroup will use all datafiles in the filegroup. Any table in FG1 resides equally on Datafile1, Datafile2 and Datafile3. If you need to control placement you need to create distinct filegroups. To remove a file from a file group use DBCC SHRINKFILE EMPTYFILE.

share|improve this answer
    
Clarifying, a table is stored per filegroup. Not per file. So any table/index will be spread over all files in that filegroup –  gbn May 21 '13 at 10:20
2  
There's no guarantee that tables will be spread equally across the files. I can think of a few situations where that isn't the case (index rebuild being one). –  Thomas Stringer May 21 '13 at 11:35
    
@ThomasStringer: they are spread equally from a logical point of view. Actual allocation is irrelevant here and I very much intentionally did not want to talk about that. An answer should contain what OP needs to know, not everything you and I know. –  Remus Rusanu May 21 '13 at 11:45
    
Good point and agreed. Also, good answer, +1. –  Thomas Stringer May 21 '13 at 12:05
    
Out of the 3 files within the Filegroup, two of them sit on SATA drive and one sits on FC. I m testing queries against two similar tables within the same FG and even after the exec plan for each query is same, the execution time is different and i m suspecting that one of the tables in on SATA and other is on FibreChannel. –  Amam May 22 '13 at 4:04
show 1 more comment

No matter even if your data is spread over any number of data files but still you can use INFORMATION_SCHEMA.TABLES to get the list of tables.

TABLES

Overview The INFORMATION_SCHEMA.TABLES view allows you to get information about all tables and views within a database. By default it will show you this information for every single table and view that is in the database.

Explanation This view can be called from any of the databases in an instance of SQL Server and will return the results for the data within that particular database.

The columns that this view returns are as follows:

Column name Data type Description

  • TABLE_CATALOG nvarchar(128) Table qualifier.
  • TABLE_SCHEMA nvarchar(128) Name of schema that contains the table.
  • TABLE_NAME sysname Table name.
  • TABLE_TYPE varchar(10) Type of table. Can be VIEW or BASE TABLE.

(Source: SQL Server 2005 Books Online)


Here is an example of data that was pulled from the AdventureWorks database. This data was pulled using this query:

SELECT * FROM INFORMATION_SCHEMA.TABLES

To only show a list of tables you would use this query:

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'

To only show a list of only the view you would use this query:

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'VIEW' 
share|improve this answer
    
1. The case against INFORMATION_SCHEMA views - some details about these views. 2. OP has requested that he wants the table placement in file groups and data files, not the table standard metadata found in Information_Schema views. –  Marian May 21 '13 at 8:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.