Solved

Which tables belong to which filegroup in SQL Server 2008

Posted on 2013-12-31
3
491 Views
Last Modified: 2013-12-31
I use the following code to list tables and filegroups. This lists both user and system tables but I only want to list the user tables (which are prefixed 'T_').


select tablename = object_name(object_id),Data_located_on_filegroup = d.name  
from sys.data_spaces d
join sys.indexes i on d.data_space_id = i.data_space_id
where i.index_id < 2
ORDER by tablename DESC
0
Comment
Question by:TimHudspith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Habib Pourfard earned 500 total points
ID: 39748001
try the following:
SELECT  tablename = t.name ,
        Data_located_on_filegroup = d.name
FROM    sys.filegroups d
        JOIN sys.indexes i ON i.data_space_id = d.data_space_id
        JOIN sys.tables t ON t.object_id = i.object_id
WHERE   i.index_id < 2
        AND t.type = 'U'
        AND t.name LIKE 'T_%'
ORDER BY tablename DESC

Open in new window

0
 

Author Comment

by:TimHudspith
ID: 39748055
That only returned one record, but in fact I have six tables, so I looked at the two tables that your code refers to. In sys.data_spaces I have 3 filegroups: primary (data_space_id = 1), filestream (2), secondary (3). However, with one exception, my user tables in sys.tables have a data_space_id value of 0, which of course doesn't represent any of the actual filegroups.

I'm new to SQL server and have done a bit of experimenting with filegroups and tables, also I didn't have SP3 installed when doing this. I remember getting some odd messages when trying to refresh/save objects so I expect it's connected to that.

What I'm aiming at ultimately is moving my user tables to the secondary filegroup.
0
 

Author Comment

by:TimHudspith
ID: 39748087
Actually, disregard what I said. It works.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question