简体   繁体   中英

Merge SQL databases keeping one index

I have to recover a SQL 2008 R2 database for a POS system that broke down without proper backups in place. The .BAK file has been recovered, but was corrupted. However, I was able to retrieve most of the data and get it back into usable shape.

My problem now is as following: I have database A, which is a fresh installation for the POS system, and database B, which is the recovered .BAK file. Most of the tables in B are missing their index values, while A has an intact structure, but is (obviously) lacking all the valuable data.

How would I go about merging the two, so that I get a fully-indexed database with the correct structure?

One simple way is to use the builtin command line tool tablediff.exe . It can compare two tables/views, and print out the differences.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM