查看表和索引所在文件组
最近有个需求涉及根据表名或者索引名字拿到文件分组名字
SELECT 'table_name' = OBJECT_NAME(i.id),
i.indid,
'index_name' = i.name,
i.groupid,
'filegroup' = f.name,
'file_name' = d.physical_name,
'dataspace' = s.name
FROM sys.sysindexes i,
sys.filegroups f,
sys.database_files d,
sys.data_spaces s
WHERE OBJECTPROPERTY(i.id, 'IsUserTable') = 1
AND f.data_space_id = i.groupid
AND f.data_space_id = d.data_space_id
AND f.data_space_id = s.data_space_id
ORDER BY f.name,
OBJECT_NAME(i.id),
groupid