Blog Post

Azure Database Support Blog
2 MIN READ

Handling Duplicate Metadata Errors When Re‑Enabling Mirroring in Azure SQL Database

santhosh_reddy's avatar
Jan 22, 2026

In some environments, users follow a weekly workflow where they drop a table and later re-enable mirroring for that table. While this works most of the time, it can occasionally lead to metadata inconsistencies especially when using Fabric Mirrored Databases.

 

Recently, during such a weekly refresh cycle, enabling mirroring failed for one specific table, resulting in a duplicate key error inside system metadata tables.

Below is a detailed walkthrough of the issue, root cause, and final resolution.

A user uses a mirrored database with multiple replicated tables. During the mirroring refresh cycle, the table [test] failed to re-enable replication and showed the following error:

Error Code: SqlError
Type: UserError
Message: Cannot insert duplicate key row in object 'sys.change_feed_tables'
with unique index 'pk_change_feed_tables'.
The duplicate key value is (*******-****-****-****-******).
Time of Failure: 2025-12-01 1:17:19.4559990

Why This Happens

When a table is dropped, the system should automatically remove:

  • Change feed configurations
  • Metadata entries
  • Internal table identifiers

However, in this scenario, some of the old metadata in sys.change_feed_tables was not cleaned up. This caused a duplicate key conflict, preventing the system from enabling the change feed again.

 Resolution:

To fix the metadata conflict, we manually cleaned up the stale change feed entry using the following command:

 

EXEC sp_change_feed_disable_table

    @tablegroupid = '******',

    @table_id       = '********';

Once this command executed successfully:

  • The stale metadata entry was removed.
  • The table could be re-enabled for mirroring without errors.
  • Replication resumed normally.

After disabling the stale change feed entry manually, the user successfully:

  • Re-enabled mirroring for table [Test]
  • Restored normal replication flow
  • Avoided further duplicate-key metadata issues

Key Takeaways for Weekly Refresh Scenarios

  • Dropping and re-adding replicated tables can create metadata inconsistencies, especially if the refresh happens quickly.
  • If you see errors related to sys.change_feed_tables, it usually indicates stale metadata.
  • The fix generally involves manually cleaning up change feed metadata using sp_change_feed_disable_table.

 

Disclaimer: Please be aware that the products and options discussed in this article are subject to change. This article discusses the 

handling duplicate metadata errors when re‑enabling Mirroring in Azure SQL Database.

References:

sys.sp_change_feed_disable_table (Transact-SQL) - SQL Server | Microsoft Learn

Microsoft Fabric Mirrored Databases from Azure SQL Database - Microsoft Fabric | Microsoft Learn

Published Jan 22, 2026
Version 1.0
No CommentsBe the first to comment