SQL Server 查看使用Primary的Filegroup的DB

查看使用 PRIMARY的Filegroup的DB
SELECT  *  FROM 

select  fg=filegroup_name(a.data_space_id),  tbl=object_name(p.object_id),  idx=i.name 
from  sys.allocation_units  a 
inner  join  sys.partitions  p 
on  p.partition_id  =  a.container_id 
and  p.object_id  >  1024  -- arbitary, just to filter out system objects 
and  a.type  =  2 
left  join  sys.indexes  i 
on  i.object_id  =  p.object_id 
and  i.index_id  =  p.index_id 
union  all 
select  fg=filegroup_name(a.data_space_id),  tbl=object_name(p.object_id),  idx=i.name 
from  sys.allocation_units  a 
inner  join  sys.partitions  p 
on  p.hobt_id  =  a.container_id 
and  p.object_id  >  1024  -- arbitary, just to filter out system objects 
and  a.type  in  (1,  3) 
left  join  sys.indexes  i 
on  i.object_id  =  p.object_id 
and  i.index_id  =  p.index_id 
)A 
WHERE  fg='PRIMARY' 

原文地址:https://www.cnblogs.com/Fly446854715/p/4125824.html