Solved

Which tables belong to which filegroup in SQL Server 2008

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Update a text value in another table 10 42
New to SSRS, extremely slow running report. 8 20
Sql Query 6 68
SQL Select to Group and Filter Data 5 15
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

821 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