如何检查数据是否已从临时表正确复制到主表中 [英] How to check a data has correctly copied from temp table into master table

查看:138
本文介绍了如何检查数据是否已从临时表正确复制到主表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用C#和Sql Server 2005.

我有临时表,所有数据都将保存到主表。



我必须检查所有数据是否已从temp复制到master。

如果不是我删除了特定数据然后重新重新插入主人







i已写入一次检查。

但我不认为这是正确的方式becoz第一次如果数据没有正确插入然后我将比较和重新插入第二次但在那之后我还需要检查完整性





请帮我解决这个问题



问候

Nirmala Saravanan



Iam using C# and Sql Server 2005 .
I have temp table from which all the data will be saved to master table.

I have to check whether all the data has copied from temp to master.
if not i have delete that particular data and reinsert again in master



i have written for one time checking.
But i don't think that's right way becoz for first time if data not properly inserted then i will compare and reinsert second time but after that also i need check for integrity


Pls help me how to solve this

Regards
Nirmala Saravanan

推荐答案

完成插入后,但在处理临时表之前,您可以尝试使用类似

Once you have completed your insert, but before disposing of the temporary table you could try using something like
SELECT COUNT(*) FROM [temp_table] WHERE ComboKey NOT IN [master_table]



其中ComboKey​​是一些键值组合,可以唯一标识您尝试插入的记录。



您希望返回值0。任何非零回报都表示您没有插入所有内容。



总体而言,您可能最好使用交易...看看 SQL Server事务和错误处理 [ ^ ]


插入之前在主表中获取行数并将其保存在变量中。



然后在另一个变量中保留temparary表行的数量。





插入后检查主表的数量



才算数+ temptablecount



你可以验证,

如果没有匹配删除行..
before inserting in master table get the count of rows and keep it in a variable.

then in another variable keep the count of temparary table rows.


after inserting check the count of master table

before count+ temptablecount

you can verify ,
if didnt match delete the rows..


这篇关于如何检查数据是否已从临时表正确复制到主表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆