"Tablediff" command line tool

Source: Internet
Author: User
"Tablediff" command line tool

The "tablediff" tool allows you to compare the content of two tables. It was originally developed to replicate scenarios to help diagnose differences, but it is also useful for other situations. When the data in two tables may be the same or similar, this tool can help determine whether they are the same, and if they are different, it can identify which data in the table is different.

The syntax of "tablediff" is as follows:

Tablediff
[-? ] |
{
-Sourceserver source_server_name [\ instance_name]
-Sourcedatabase source_database
-Sourcetable source_table_name
[-Sourceschema source_schema_name]
[-Sourcepassword source_password]
[-Sourceuser source_login]
[-Sourcelocked]
-Destinationserver destination_server_name [\ instance_name]
-Destinationdatabase subscription_database
-Destinationtable destination_table
[-Destinationschema destination_schema_name]
[-Destinationpassword destination_password]
[-Destinationuser destination_login]
[-Destinationlocked]
[-B large_object_bytes]
[-BF number_of_statements]
[-C]
[-DT]
[-Et table_name]
[-F [file_name]
[-O output_file_name]
[-Q]
[-RC number_of_retries]
[-Ri retry_interval] 5
[-Strict]
[-T connection_timeouts]
}

The "tablediff" syntax requires the connection information of the source and target to be compared. This information includes the server, database, and table information to be compared. The connection information must be provided for SQL Server Authentication, but it can be left blank if Windows authentication is available. The source and target parameters can be two different servers or the same server. The "tablediff" tool can run on one machine, neither the source nor the target.

To illustrate the role of the tool, let's look at a simple comparison example. We use the "adventureworks2008r2" database. To create more useful data, the simplest way is to copy the Content Query in one table to another, and then update some row content in one table. The following "select" Statement copies the "addresstype" table in the "adventureworks2008r2" database. The copied new table is "addresstypecopy ":

Select *
Into person. addresstypecopy
From person. addresstype

In addition, the following statement updates the two rows in the addresstypecopy table (for test purposes) so that you can use the tablediff tool to identify the differences between them:

Update person. addresstypecopy
Set Name = 'billing new'
Where addresstypeid = 1
Update person. addresstypecopy
Set Name = 'shipping new ',
Modifieddate = '20140901'
Where addresstypeid = 5

The "tablediff" tool can be executed with the following parameters to identify the differences between the "addresstype" and "addresstypecopy" tables:

Tablediff-sourceserver "(local)"-sourcedatabase "adventureworks2008r2"
-Sourceschema "person"-sourcetable "addresstype"
-Destinationserver "(local)"-destinationdatabase "adventureworks2008r2"
-Destinationschema "person"-destinationtable "addresstypecopy"
-F c: \ tablediff_output.txt

The target parameter and Source parameter are the same as the preceding example. Besides the table parameters, the source table "addresstype" and the target table "addresstypecopy" are the same ". The tool uses these parameters to get the following output in the command line Prompt window:

Proxy parameter value specified by the user:

-Sourceserver (local)
-Sourcedatabase adventureworks2008r2
-Sourceschema person
-Sourcetable addresstype
-Destinationserver (local)
-Destinationdatabase adventureworks2008r2
-Destinationschema person
-Destinationtable addresstypecopy
-F c: \ tablediff_output
Table [adventureworks2008r2]. [person]. [addresstype] On (local)
And table [adventureworks2008r2]. [person]. [addresstypecopy] On (local)
Have 2 differences.
Fix SQL written to c: \ tablediff_output. SQL.
Err addresstypeid col
Mismatch 1 Name
Mismatch 5 modifieddate name
The requested operation took 0.296875 seconds.

In the output content, the summary of the used parameters is displayed first, and the comparison result is displayed. In this example, it finds two differences, because we have previously updated the addresstypecopy table. In addition, the "-F" parameter is used in this example to make the "tablediff" Tool Output an SQL file that can be used to correct the differences in the target table. In this example, the content of the output file is as follows:

-Host: (local)
-Database: [adventureworks2008r2]
-Table: [person]. [addresstypecopy]
Set identity_insert [person]. [addresstypecopy] On
Update [person]. [addresstypecopy]
Set [name] = 'billing'
Where [addresstypeid] = 1
Update [person]. [addresstypecopy]
Set [modifieddate] = '2017-06-01 00:00:00. 000 ',
[Name] = 'shipping' where [addresstypeid] = 5
Set identity_insert [person]. [addresstypecopy] Off

Remember, we can use the tablediff tool to implement several different comparison types. The "-Q" parameter triggers a quick comparison to compare only the number of records and find the differences between objects. The "-strict" parameter requires that the structure of each table be the same during comparison. If this parameter is not used, this tool allows some columns to have different data types, as long as they meet the needs of Automatic Data Type ing (for example, int can be compared with bigint ).

The "tablediff" tool can be used for comparison of many different types. How you use this tool depends on several factors, including the number and type of data to be compared.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.