合并 SQL 个数据库,保留一个索引

Merge SQL databases keeping one index

我必须为 POS 系统恢复 SQL 2008 R2 数据库,该系统在没有适当备份的情况下发生故障。 .BAK 文件已恢复,但已损坏。但是,我能够检索大部分数据并将其恢复到可用状态。

我现在的问题如下: 我有数据库 A,它是 POS 系统的全新安装,还有数据库 B,它是恢复的 .BAK 文件。 B 中的大多数表都缺少它们的索引值,而 A 具有完整的结构,但(显然)缺少所有有价值的数据。

我将如何合并两者,以便获得具有正确结构的完全索引数据库?

一种简单的方法是使用内置命令行工具tablediff.exe。它可以比较两个 tables/views,并打印出差异。

The tablediff utility is used to compare the data in two tables for non-convergence, and is particularly useful for troubleshooting non-convergence in a replication topology. This utility can be used from the command prompt or in a batch file to perform the following tasks:

  • A row by row comparison between a source table in an instance of Microsoft SQL Server acting as a replication Publisher and the destination table at one or more instances of SQL Server acting as replication Subscribers.
  • Perform a fast comparison by only comparing row counts and schema.
  • Perform column-level comparisons.
  • Generate a Transact-SQL script to fix discrepancies at the destination server to bring the source and destination tables into convergence.
  • Log results to an output file or into a table in the destination database.