如何验证两个SQL Server数据库是否包含相同的数据?
给定两个已知具有相同架构的 MS SQL 数据库,我应该如何判断它们是否包含相同的数据副本?
我使用 MS SQL Server 2008 Express,并使用 ADO.NET API 使用 C# 和 .Net 框架 v2.0 进行编码。 这两个数据库实例都位于同一 SQL Server 上。
背景:我编写了软件将数据从数据库导出到一组文件,并从这些文件重新导入数据(到数据库的另一个副本); 我想测试在往返过程中是否丢失了任何数据(更具体地说,在初始导出期间是否丢失或留下了任何数据)。
我猜想的一种粗略方法是从每个数据库中的每个表中选择 * ,然后使用客户端代码比较所选记录集。 有没有另一种方法,需要更少的客户端代码?
我找到了有关备份和恢复数据库以及有关选择和插入数据的文档,但没有注意到有关如何验证/证明往返已完全成功的文档,即如何验证是否有两个副本两个数据库中的表包含相同的数据。
Given two MS SQL databases which are known to have identical schemas, how should I tell whether they contain identical copies of the data?
I'm using MS SQL Server 2008 Express, and coding in C# and v2.0 of the .Net framework, using ADO.NET APIs. The two database instances are both on the same SQL server.
Background: I've written software to export data from a database to a set of files, and, to re-import the data from those files (into another copy of the database); I want to test whether I lost any data during the round-trip (more specifically, whether there's any data lost or left behind during the initial export).
A crude way I guess would be to SELECT *
from every table in each database, and then to compare the selected recordsets using client-side code. Is there another way, that would require less client-side code?
I've found documentation about backing up and restoring a database, and about selecting and inserting data, but haven't noticed this about how to verify/prove that a round-trip has been completely successful, i.e. how to verify whether two copies of a table in two databases contain equal data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一步是比较记录计数。 您可以快速完成此操作,
您需要对每个表执行此操作。
要比较表中的数据,我将使用 CHECKSUM< /a> 函数。
First step would be to compare record counts. You can do this with a quick
You would need to do this for every Table.
To compare the data in the tables I would use the CHECKSUM function.
RedGate 的 SQL 数据比较 可能就是答案。
RedGate's SQL Data Compare might be the answer.
您可以使用 Redgate SQL 数据比较
1>它将告诉您数据库中每个表中的数据总数
2> 它将生成一个脚本,该脚本将显示其中哪些数据不同,以便通过执行它可以使数据相同。
3>它将通过 SQL COMPARE 显示架构是否不同
4>许多功能很有用,您还可以同步两个数据库。
除此之外,Visual studio 2012还为您提供了比较数据的选项,您也可以尝试一下
You can use Redgate SQL DATA COMPARE
1>It will tell total count of data in each table of your database
2> It will generate a script which will show what data is different in it so that by executing it you can make data same.
3>It will show if schema is different by SQL COMPARE
4>Lots of features are useful you can also sync two database.
Addition to it Visual studio 2012 gives you an option to compare the data ,You can try that also