Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Fixing SQL Server Error 606: Filegroup ID Inconsistency

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server Error 606 occurs when a table or index references a filegroup ID that doesn’t exist in the database schema, causing corruption warnings. The simplest fix is to recluster the table or drop and recreate it with correct filegroup assignments, but deeper corruption may require rebuilding the database or checking file consistency. Here’s how to diagnose, repair, and prevent this issue.

What You'll Need

  • A SQL Server Management Studio (SSMS) or equivalent client (e.g., Azure Data Studio, third-party tools like Red Gate SQL Tools)
  • Administrative permissions to modify database objects
  • The database backup or transaction log files (if restoring is required)
  • Optional: SQL Server Error Logs or Extended Events for deeper inspection

Step-by-Step

  1. Verify the exact error details

    Open SSMS, connect to the database, and run this query in a new query window to see the precise error context: SELECT * FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 1) WHERE is_corrupted = 1;

    This will return tables/indexes marked as corrupted. If no results appear, check the SQL Server Error Log for broader warnings or run: DBCC CHECKDB WITH ALL_ERRORMSGS;

  2. Check filegroup assignments Run these queries to confirm filegroup IDs for the problematic table/index: SELECT OBJECT_NAME(object_id) AS TableName, index_id, filegroup_id, name AS filegroup_name FROM sys.indexes WHERE object_id = OBJECT_ID('Schema.TableName') AND index_id > 0;

    Compare these IDs with the actual filegroup structure in your database: SELECT name, type_desc FROM sys.filegroups;

    If mismatches exist, proceed to Step 3 or 4 below.

  3. Recluster the table (safe first step) For most cases, reclustering resolves the issue without data loss:
    1. Right-click the table in Object Explorer, select Design.
    2. Go to the File Group tab in the designer.
    3. Click Recluster. Confirm the prompt.

    This refreshes the filegroup mapping without altering the physical layout. Repeat for all systematically clustered indexes.

  4. Drop and recreate the table (if reclustering fails)

    If the table remains corrupted, drop and recreate it with explicit filegroup references:

    1. Backup the table before proceeding: CREATE TABLE NewTable AS SELECT * FROM OldTable;
    2. Drop the original table: DROP TABLE OldTable;
    3. Recreate with targeted filegroup assignment: CREATE TABLE NewTable ( Column1 INT, Column2 VARCHAR(50) ) ON FILEGROUP = 'TargetFileGroup';

      Replace 'TargetFileGroup' with the correct filegroup name.

  5. Rebuild the database (for severe corruption)

    If the issue persists across multiple tables, the database may be physically corrupted. Rebuild it using:

    1. Create a new database (from backup) on the same server.
    2. Restore the schema and data from backup into the new database.
    3. Reattach the existing logs (if applicable) to preserve transaction history.

    Use this command to verify filegroup consistency before finalizing: DBCC CHECKDB('NewDatabase') WITH ALL_ERRORMSGS;

Common Mistakes

  • Skipping the initial DBCC CHECKDB: Without confirming corruption exists, you might waste time on steps that don’t address the root cause (e.g., dropping a non-corrupted table). Always validate with DBCC before proceeding to more invasive operations.
  • Incorrect filegroup references: Using the wrong filegroup ID (e.g., a deleted or renamed group) during recreation will propagate the error. Double-check with the sys.filegroups view before assigning IDs.
  • Ignoring transaction logs: If the database is in a recoverable state during corruption, failing to log the operation when dropping/creating tables risks transaction loss. Always use explicit backups or temporary tables during schema changes.
  • Overlooking filegroup constraints: Some filegroups may have limitations (e.g., max file size) that conflict with your table’s storage needs. Verify with: SELECT name, max_size_in_bytes FROM sys.filegroups;

Tips

  • Prevention:
    1. Schedule regular DBCC checks during low-traffic periods.
    2. Use filegroup isolation during major schema changes to avoid ID conflicts.
    3. Implement a change control process for table/filegroup modifications.
  • Performance impact: Rebuilding a large database can delay production workloads. Test recovery steps in a staging environment first.
  • Alternative tools: For complex scenarios, consider third-party tools like SQL Diag Studio or Red Gate’s SQL Debloat Tool to identify filegroup-related bottlenecks.

Troubleshooting

If reclustering doesn’t resolve the issue: The corruption may stem from underlying file system issues (e.g., disk errors). Check:

  1. Run disk checks on the SQL Server’s drives.
  2. Verify the transaction log isn’t corrupted: SELECT * FROM sys.dm_db_log_recovery;
  3. Consider using DBCC CHECKFILE to inspect individual files: DBCC CHECKFILE(1); (Replace 1 with the file ID from sys.database_files).

If the database won’t start: This indicates severe corruption. Attempt:

  1. Use SQL Server Recovery Manager (if available) to back up the database.
  2. Restart the SQL Server service and attempt recovery with: ALTER DATABASE DatabaseName SET EMERGENCY; Then restore from backup to the original location.
  3. If no backups exist, restore from a system snapshot (if supported by your OS)

Frequently Asked Questions

Why does SQL Server show error 606 after a restore?

Error 606 during restore typically occurs when the filegroup IDs in the database script don’t match the target server’s filegroup structure. Verify the target server’s filegroup table before restoring by running: SELECT name FROM sys.filegroups; Compare with the source database’s filegroup assignments. Either match the target server’s structure or recreate the database on the source server before restoring.

How can I force SQL Server to recognize a new filegroup without dropping tables?

You can’t directly assign filegroups to existing tables without dropping/recreating them. Instead:

  1. Create a new filegroup: CREATE FILEGROUP NewFileGroup;
  2. Attach the new file to the filegroup: ALTER DATABASE CurrentDB ADD FILE (NAME = 'NewFile', PATH = 'C:\NewPath\') TO FILEGROUP NewFileGroup;
  3. For tables, recreate them with the new filegroup reference as shown in Step 4 above.

What if I’ve deleted a filegroup but tables still reference it?

The tables will remain functional but may appear corrupted in DBCC CHECKDB. To resolve:

  1. Drop the tables from the deleted filegroup: ALTER TABLE TableName MOVE TO 'DefaultFileGroup'; (Replace 'DefaultFileGroup' with the next available filegroup)
  2. Update your schema design to avoid referencing the deleted group.

Will reclustering affect primary key indexes?

No. Reclustering only refreshes the physical mapping of clustered indexes (typically data pages). Primary keys are always clustered by default and won’t be affected by this process.

How do I check if a table is using a specific filegroup?

Run this query to verify a table’s filegroup assignments: SELECT t.name AS TableName, i.name AS IndexName, tf.name AS FilegroupName FROM sys.tables t JOIN sys.indexes i ON t.object_id = i.object_id JOIN sys.filegroups tf ON i.filegroup_id = tf.filegroup_id WHERE t.name = 'YourTableName'; Replace 'YourTableName' with your actual table name.

Can I use this method to fix a filegroup issue on Azure SQL?

Yes, but with caveats. Azure SQL’s filegroups are managed differently than on-premises:

  1. Use Azure Data Studio or SQL Server Management Studio (with Azure connectivity).
  2. For temporary fixes, consider moving data to a different filegroup using: ALTER TABLE TableName MOVE TO FILEGROUP 'NewFileGroup'; (Requires permissions)
  3. For permanent fixes, recreate the database in a new location with matching filegroup structure.
Azure doesn’t support dynamic filegroups like on-premises, so all tables must use one filegroup per database.