Perform checksum to check if source table rows are loaded in target table
I'm trying to load data from old SQL Server 2000 to new SQL Server 2014. I need to do a checksum to check if all the source data is loaded in the target database (SQL Server 2014).
I've created the insert statement for the same which works. I need to use checksum to make sure all the source rows are loaded in the target table. Can somebody give me a hand on this?
Any help is appreciated.
Here is my insert statement:
INSERT INTO [Test].[dbo].[Order_tab]
([rec_id]
,[date_loaded]
,[Name1]
,[Name2]
,[Address1]
,[Address2]
,[City]
,[State]
,[Zipcode]
,[e_Name1])
SELECT s.[rec_id]
,s.[date_loaded]
,s.[Name1]
,s.[Name2]
,s.[Address1]
,s.[Address2]
,s.[City]
,s.[State]
,s.[Zipcode]
,ENCRYPTBYKEY(key_guid('EncryptionKey'),s.[Name1])
FROM [LinkedServer].[SourceTest].[dbo].[Order_tab] s
left join [Test].[dbo].[Order_tab] d on d.rec_id= s.rec_id
where d.rec_id IS NULL
Hi this is a very naiv solution, but if you only need a one time check, it is fast :)
SELECT SUM([rec_id])
FROM [Test].[dbo].[Order_tab]
And then compare it to:
SELECT SUM([rec_id])
FROM [LinkedServer].[SourceTest].[dbo].[Order_tab]
If you got everything over the SUM
of the Id's should be the same :)
上一篇: 将iPhone / iPad应用降级至iPhone
下一篇: 执行校验和以检查源表行是否加载到目标表中