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
Yasir Arsanukayev
  • 3,155
  • 3
  • 23
  • 30
Amam
  • 399
  • 1
  • 5
  • 11

2 Answers2

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.

Remus Rusanu
  • 52,054
  • 4
  • 96
  • 172
-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' 
Marian
  • 15,741
  • 2
  • 62
  • 75
user2404431
  • 117
  • 2