Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Which tables belong to which filegroup in SQL Server 2008

Posted on 2013-12-31
3
Medium Priority
?
507 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

971 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