Solved

Which tables belong to which filegroup in SQL Server 2008

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
encyps queries mssql 15 27
SQL Server 2008 R2 - Updating Table/Fields Documentation 3 30
Azure SQL DB? 3 22
Slow SQL query 12 29
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

743 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

16 Experts available now in Live!

Get 1:1 Help Now