SQL Data Comparison with Visual Studio 2010

SQL Data Comparison with Visual Studio 2010

By: Arshad Ali -- 8/23/2010

Rating:
Win a Color Nook with SQL Server eBooks

Problem
In my last tip "SQL Schema Comparison with Visual Studio 2010", I showed how to compare schema objects, synchronize them or get incremental deployment scripts. This is good way to synchronize the schema objects between two different environments, but we also often need to compare and synchronize the data that tables (which have the same structure) contain. For example we normally define some master data in a development environment during development and would like the same data to be deployed/inserted/updated to Test/QA/UAT/Production environments after development. So how can we do this, how we can compare data of the tables between different databases and generate data synchronization or incremental data deployment scripts?

Solution
Although there are several different tools available for data comparison (some you need to purchase and some are free) I am going to discuss the Microsoft Visual Studio Database edition for data comparison.

Microsoft Visual Studio Database edition offers several features for database development, for example you can create a database project which is nothing but an offline representation of a database for database development and version control, Database Unit Testing, Code Analysis, Schema Comparison, Data Comparison etc. In this demonstration I am going to show how Data Comparison works on Visual Studio 2010 Ultimate edition although you can do the same with Visual Studio 2005/2008 Database edition too.

Open the Microsoft Visual Studio IDE (Integrated Development Studio) and you will see a "Data" menu in the menu bar depending on the Microsoft Visual Studio edition you have installed (for more details click here). Select Data Compare under Data menu and then New Data Comparison as shown below.

SQL Data Comparison with Visual Studio 2010_第2张图片

You will see a dialog box like this, here you need to specify your source and target database (for which you need to set up a connection to your SQL Server instance). And next you can specify the data comparison options, for example do you want to list all the different records on the result screen or/and records which only exist in source or/and records which only exist in target or/and identical records between source and target. Click on Next to move ahead in the wizard.

SQL Data Comparison with Visual Studio 2010_第3张图片

On the next screen you can select which tables or views you want to be considered during the data comparison, also you can individually select the columns which you want to be part of the comparison as you can see below. The source and target tables/views must have a primary/unique key which is used as a comparison key during the data comparison. If the table/view has multiple indexes you can select which one will be considered as the comparison key here also.

SQL Data Comparison with Visual Studio 2010_第4张图片

The moment you click on the Finish button in the above screen, it will start doing the data comparison for the selected objects and finally will show the comparison result. You will notice a new tool bar on top, some of the options of this new tool bar are: you can filter out the data comparison result as you can see in the image below, you can synchronize your target tables' data by writing updates to it, you can export your data synchronization/incremental update script to a file or to the editor.

SQL Data Comparison with Visual Studio 2010_第5张图片

The data comparison result screen will look like the image shown below. On the top pane there are five columns; the first column shows the name of the objects considered in the comparison, second column tells the number of different records between source and target, third column tells the number of records which only exist in source likewise the fourth column gives the number of records which only exist in target and finally the fifth column gives the total number of identical records between source and target.

The next pane has four different tabs, if you notice in the "Different Records" tab the first column "Update" is a check box which you can select/unselect to consider that record in synchronization, next you will see the primary/unique key and then later on all the columns appear twice, the first appearance shows the column value from the source and the second appearance shows the column value from the target. This way you can easily see/compare the changes.

The bottom pane shows the target database data update script depending on the basis of the selection you used above. As you can see, I have two updates and two new records at the source and the scripts appear in this pane. If you are not able to see it or want to refresh it, click on the "Refresh Update Script" icon on the toolbar to display or to refresh the changes.

Note:

  • To compare data between source and target you need to have a primary/unique key or unique constraints on both tables i.e. on source and target tables.
  • Your table might have primary key along with other unique keys, so you can select which key you would like to use as the comparison key in the second page of the wizard.
  • The name, owner and structure must be the same for both source and target tables to appear on second page of the wizard for data comparison.
  • Even though SQL Server is case-insensitive, by default, the data comparison is case sensitive when considering name and owner of the table/view.
0
0
猜你在找
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
快速回复 TOP
    个人资料
    SQL Data Comparison with Visual Studio 2010_第6张图片
    tuwen
    • 访问:1084143次
    • 积分:16399
    • 等级:
    • 排名:第319名
    • 原创:583篇
    • 转载:87篇
    • 译文:1篇
    • 评论:608条
    文章分类
  • Asp.net(16)
  • C/C++(2)
  • InstallShield(0)
  • Web前端(Javacript, JQuery, CSS)(6)
  • 活动,大会,书籍,程序人生(6)
  • 架构师(4)
  • Database(2)
  • Window Azure(2)
  • Velocity(网页响应速度)(0)
  • C#(0)
  • JQuery(4)
  • 活动(1)
  • 大会(1)
  • 书籍(1)
  • 程序人生(1)
    文章存档
  • 2015年04月(1)
  • 2015年01月(1)
  • 2013年09月(4)
  • 2012年10月(2)
  • 2012年08月(1)
  • 2012年01月(1)
  • 2011年11月(3)
  • 2011年10月(5)
  • 2011年09月(4)
  • 2011年08月(1)
  • 2011年07月(2)
  • 2011年05月(3)
  • 2011年04月(3)
  • 2011年03月(23)
  • 2011年02月(14)
  • 2011年01月(16)
  • 2010年12月(11)
  • 2010年11月(5)
  • 2010年10月(5)
  • 2010年09月(5)
  • 2010年08月(14)
  • 2010年07月(7)
  • 2010年06月(4)
  • 2010年05月(19)
  • 2010年04月(16)
  • 2010年03月(35)
  • 2010年02月(30)
  • 2010年01月(24)
  • 2009年12月(18)
  • 2009年11月(5)
  • 2009年10月(7)
  • 2009年09月(5)
  • 2009年08月(1)
  • 2009年07月(2)
  • 2009年06月(15)
  • 2009年05月(12)
  • 2009年04月(5)
  • 2009年03月(18)
  • 2009年02月(2)
  • 2009年01月(6)
  • 2008年12月(8)
  • 2008年11月(16)
  • 2008年10月(7)
  • 2008年09月(13)
  • 2008年08月(9)
  • 2008年07月(9)
  • 2008年06月(3)
  • 2008年05月(6)
  • 2008年04月(23)
  • 2008年03月(43)
  • 2008年02月(4)
  • 2008年01月(36)
  • 2007年12月(9)
  • 2007年11月(32)
  • 2007年10月(30)
  • 2007年09月(28)
  • 2007年08月(24)
  • 2007年07月(16)
    阅读排行
  • 北京公安局出入境管理处地址(67893)
  • 关于正则表达式匹配任意字符(32074)
  • C++ 异常处理 入门(28590)
  • OUTLOOK的通讯录导入问题(17597)
  • 12种性格导致贫穷(15828)
  • ASP.NET自定义错误页面(15441)
  • TcpTimedWaitDelay和MaxUserPort设置(13309)
  • C++如何读取txt文件,文件比较大想一行一行的读。(12676)
  • Vc中添加lib和h文件(12520)
  • ASP.NET水晶报表从入门到灵活应用(10996)
    评论排行
  • 12种性格导致贫穷(238)
  • 你最应该雇佣的程序员的十个特征(21)
  • ASP.NET自定义错误页面(14)
  • ASP.NET水晶报表从入门到灵活应用(14)
  • Code Review中的几个提示(13)
  • Javascript中eval函数的用法(13)
  • 设计模式(博客园精化集)(12)
  • 北京公安局出入境管理处地址(11)
  • C# webservice调用方法总结(10)
  • C++ 异常处理 入门(10)
    推荐文章
    • *Android自定义ViewGroup打造各种风格的SlidingMenu
    • * Android 6.0 运行时权限处理完全解析
    • * 数据库性能优化之SQL语句优化
    • *Animation动画详解(七)——ObjectAnimator基本使用
    • * Chromium网页URL加载过程分析
    • * 大数据三种典型云服务模式
    最新评论
  • C#数组中CopyTo()和Clone()的区别(转)

    Tany_DY: 不错,理解了,谢谢楼主

  • 阅读别人的代码(看别人写的,感觉很好,分享)

    dandingwangzi: 不错

  • Vc中添加lib和h文件

    yuan_a_yuan: 谢谢~

  • 关于正则表达式匹配任意字符

    Matthrew: 哥们。如果我想匹配这个2134,8564,这个该怎么写??

  • 20个值得开发人员关注的jQuery技术网站和博客

    ironxue: 好东西,顶楼主,收藏了。

  • 《ASP.NET MVC案例教程》索引贴

    ZHOUCHAOQIANG: 学习了

  • java的ArrayList使用

    springmvc_springdata: java arraylist demo教程源代码下载:http://www.zuidaima.com...

  • 关于正则表达式匹配任意字符

    itouch4: @lijunwyf:的确写反了

  • 使用Json2.js的test

    liuweihug: json序列化反序列化插件-json2.js 介绍和使用 - 前端编程 - IT工作生活这点事。Ju...

  • WebChart实现折线,柱状,扇形图--web chart控件

    suifeng214: 东西蛮好的 直接引用就行 不错

你可能感兴趣的:(SQL Data Comparison with Visual Studio 2010)