我不知道您的测试的复杂性,但是,回滚测试期间所做的更改可能会对您有所帮助(据我了解,主要困难是为测试设置初始状态)?
-- The table from old database
CREATE TABLE [dbo].[People]
(
[Id] [int] NOT NULL PRIMARY KEY,
[FullName] [nvarchar](100) NOT NULL
)
-- The table from new database
CREATE TABLE [dbo].[People](
[Id] [int] NOT NULL PRIMARY KEY,
[FirstName] [nvarchar](100) NOT NULL,
[LastName] [nvarchar](100) NULL
)
样本测试(应将所有不存在的记录转移到旧表中):
BEGIN TRAN
INSERT INTO
[Old_Database].[dbo].[People]
SELECT
New_People.[Id],
(New_People.[FirstName] + ' ' + New_People.[LastName]) AS FullName
FROM
[New_Database].[dbo].[People] AS New_People
WHERE
NOT EXISTS(SELECT [Id] FROM [Old_Database].[dbo].[People] WHERE [Old_Database].[dbo].[People].[Id] = New_People.Id)
IF (@@ROWCOUNT = 0)
PRINT('Failed!');
ELSE
PRINT('Passed.');
-- We can look, what was changed
SELECT * FROM [Old_Database].[dbo].[People]
-- Do not commit the changes. This allows to run test many times
ROLLBACK TRAN