tableDiff的用法(转)
--创建测试表
CREATE TABLE Tmp
(
ID int PRIMARY KEY,
Account varchar(32),
CharName varchar(32)
)
GO
--插入测试数据
INSERT Tmp
SELECT 1,'account1','CharName1'
UNION ALL SELECT 2,'account2','CharName1'
UNION ALL SELECT 3,'account3','CharName1'
GO
--创建Check表
CREATE TABLE Tmp_Check
(
ID int PRIMARY KEY,
Account varchar(32),
CharName varchar(32)
)
GO
INSERT Tmp_Check
SELECT 1,'account11','CharName11'
CREATE TABLE Tmp
(
ID int PRIMARY KEY,
Account varchar(32),
CharName varchar(32)
)
GO
--插入测试数据
INSERT Tmp
SELECT 1,'account1','CharName1'
UNION ALL SELECT 2,'account2','CharName1'
UNION ALL SELECT 3,'account3','CharName1'
GO
--创建Check表
CREATE TABLE Tmp_Check
(
ID int PRIMARY KEY,
Account varchar(32),
CharName varchar(32)
)
GO
INSERT Tmp_Check
SELECT 1,'account11','CharName11'
使用CMD到
C:\Program Files\Microsoft SQL Server\100\COM有tablediff.exe 命令
运行
tablediff -sourceserver "localhost" -sourcedatabase "kk" -sourceschema "dbo" -sourcetable "Tmp" -sourceuser "sa" -sourcepassword "1" -destinationserver "localhost" -destinationdatabase "kk" -destinationschema "dbo" -destinationtable "Tmp_Check" -destinationuser "sa" -destinationpassword "1" -f "c:\Test.sql"
执行结果
-- Host: localhost
-- Database: [kk]
-- Table: [dbo].[Tmp_Check]
UPDATE [dbo].[Tmp_Check] SET [Account]=N'account1',[CharName]=N'CharName1' WHERE [ID] = 1
INSERT INTO [dbo].[Tmp_Check] ([Account],[CharName],[ID]) VALUES (N'account2',N'CharName1',2)
INSERT INTO [dbo].[Tmp_Check] ([Account],[CharName],[ID]) VALUES (N'account3',N'CharName1',3)
-- Database: [kk]
-- Table: [dbo].[Tmp_Check]
UPDATE [dbo].[Tmp_Check] SET [Account]=N'account1',[CharName]=N'CharName1' WHERE [ID] = 1
INSERT INTO [dbo].[Tmp_Check] ([Account],[CharName],[ID]) VALUES (N'account2',N'CharName1',2)
INSERT INTO [dbo].[Tmp_Check] ([Account],[CharName],[ID]) VALUES (N'account3',N'CharName1',3)