如何避免重复进入数据库 [英] How to avoid duplicate entry into database

查看:81
本文介绍了如何避免重复进入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用一个存储过程将一个表中的数据插入到另一个表中,并且我们从两个SQL服务器作业调用相同的存储过程

现在我们面临着将重复数据插入到表中的问题。我们考虑这个因为相同的存储过程而导致两个SQL作业调用,是否可能从两个SQL作业并行执行相同的存储过程?。如果是,那么请你给我们解决方案吨避免重复输入表。 br />


请尽快给我解决方案

Hi ,
I am using one store procedure for inserting data from one table to another with some condition, and we are calling the same Stored procedure from two SQL server jobs
Now we are facing issue like duplicate data insertion into table. We thinking of this causing because of same stored procedure is called by two SQL jobs, is it possible that same stored procedure executing in parallel from two SQL jobs?.If yes then could you please give us solution ton avoid duplicate entry into table.

Please provide me the solution ASAP it's urgent

推荐答案

在SP之前将数据插入到目标数据库检查数据是否已经存在。谷歌如何使用IF EXISTS,如果你不知道它的语法。
In the SP before you insert the data into the target database check to see if the data already exists first. Google for how to use "IF EXISTS" if you don't know the syntax for this.


你可以使用MERGE,它使用起来更安全。如果现有行已经存在,则会更新它们,如果没有任何更改,则不会发生任何事看看下面的链接。



https://www.mssqltips.com/sqlservertip/1704/using-merge-in-sql-server-to-insert-update - 同时删除/ [ ^ ]



http://www.purplefrogsystems.com/blog/2011/12 / introduction-to-t-sql-merge-basics / [ ^ ]



祝你好运!
You can use MERGE, it is much more safe to use. Existing rows will be updated if they already exist or nothing will happen if nothing changed. Check out the links below.

https://www.mssqltips.com/sqlservertip/1704/using-merge-in-sql-server-to-insert-update-and-delete-at-the-same-time/[^]

http://www.purplefrogsystems.com/blog/2011/12/introduction-to-t-sql-merge-basics/[^]

Good luck!


这篇关于如何避免重复进入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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