Rebuild indexes on Filegroup

Vijay Kumar 2,031 Reputation points
2021-03-17T00:37:30.39+00:00

How to rebuild all indexes on all tables in single file group in sql server 2016?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,264 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,597 questions
{count} votes

Accepted answer
  1. CathyJi-MSFT 21,121 Reputation points Microsoft Vendor
    2021-03-17T02:42:12.667+00:00

    Hi @Vijay Kumar ,

    Try below T-SQL;

    SELECT  
      
      sd.name AS FileGroupName,  
      
      st.name AS TableName,  
      
      si.name As IndexName,  
      
      sd.name data_space_name,  
      
      'DBCC DBREINDEX("' + SCHEMA_NAME(st.schema_id) + '.' + st.name + '", ' + QUOTENAME(si.name) + ')' AS ReIndexCommand  
      
    FROM sys.indexes si  
      
    INNER JOIN sys.tables st ON si.object_id = st.object_id  
      
    INNER JOIN sys.data_spaces sd ON si.data_space_id = sd.data_space_id  
      
       WHERE sd.name = 'filegroupname'  
    

    Quote from this similar thread REBUILD THE INDEXES BY FILE GROUP .


    If the response is helpful, please click "Accept Answer" and upvote it, thank you.

    0 comments No comments

0 additional answers

Sort by: Most helpful