Solved

Which tables belong to which filegroup in SQL Server 2008

Posted on 2013-12-31
3
468 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
  • 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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

943 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now