5

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
0

2 Answers 2

13

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.

6
  • Clarifying, a table is stored per filegroup. Not per file. So any table/index will be spread over all files in that filegroup
    – gbn
    Commented May 21, 2013 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). Commented May 21, 2013 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. Commented May 21, 2013 at 11:45
  • Good point and agreed. Also, good answer, +1. Commented May 21, 2013 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
    Commented May 22, 2013 at 4:04
-2

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' 
1
  • 1
    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
    Commented May 21, 2013 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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