How do I find out the filegroup for all tables in the database ?

  • Any suggestions ??

    I tried this script but although it works on the master and msdb databases it won't work on the database I'm interested in.

    select 'Object Name' = case si.IndID

                                     when 1 then so.Name

                                     else si.Name

                                   end,

           'Object Type' = case

                             when si.IndID < 2 then 'Table'

                             else 'Index'

                           end,

           'Table Name' = case

                            when si.IndID > 1 then so.Name

                            else ' '

                          end,

           'FileGroup Name' = sfg.GroupName,

           'System FileName' = sf.Name

      from sysfilegroups sfg inner join sysfiles sf

        on sfg.groupid = sf.groupid

     inner join sysindexes si

        on sfg.groupid = si.groupid

     inner join sysobjects so

        on si.id = so.id

     where so.type = 'U'

       and si.Name not like '#_%' escape '#'

       and so.Name not in ('dtproperties')

     order by 2 desc, 3, 1

    the error given is......

    Server: Msg 207, Level 16, State 3, Line 1

    Invalid column name 'Name'.

    Server: Msg 207, Level 16, State 1, Line 1

    Invalid column name 'IndID'.

    Server: Msg 207, Level 16, State 1, Line 1

    Invalid column name 'Name'.

    Server: Msg 207, Level 16, State 1, Line 1

    Invalid column name 'IndID'.

    Server: Msg 207, Level 16, State 1, Line 1

    Invalid column name 'Name'.

    Server: Msg 207, Level 16, State 1, Line 1

    Invalid column name 'IndID'.

    Server: Msg 207, Level 16, State 1, Line 1

    Invalid column name 'GroupName'.

    Server: Msg 207, Level 16, State 1, Line 1

    Invalid column name 'Name'.

    Server: Msg 207, Level 16, State 1, Line 1

    Invalid column name 'Name'.

    Server: Msg 207, Level 16, State 1, Line 1

    Invalid column name 'Name'.

    Any help would be greatly appreciated.

     

     

  • SELECT o.name, s.groupname

    FROM dbo.sysfilegroups s

    JOIN dbo.sysindexes i

    ON i.groupid = s.groupid

    JOIN dbo.sysobjects o

    ON i.id = object_id(o.name)

    AND i.indid in (0, 1)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply