如果记录存在,请对其进行更新.如果没有,请插入 [英] If Record Exists, Update It. If Not, Insert It

查看:71
本文介绍了如果记录存在,请对其进行更新.如果没有,请插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想插入表中不存在的数据,否则进行更新
如何在不使用storeprocedure的情况下查找表中已存在的数据
数据的插入和更新将来自临时表

谢谢inadvance


i want to insert data if it is not present in the table else update it
how to find the data already exists in the table without using storeprocedure
insert and update of data will be from a temp table

thanks inadvance

推荐答案



如果使用的是SQL 2008,则可能需要查看新的Merge命令.

MS链接:- http://technet.microsoft.com/zh-cn/library/bb510625.aspx


根据他们的网站(technet.microsoft.com):-
根据与源表的联接结果在目标表上执行插入,更新或删除操作.例如,您可以根据另一个表中的差异通过在一个表中插入,更新或删除行来同步两个表.

希望能有所帮助...尽管其他答案也很好. :)

干杯,

Steve
Hi There,

If you are using SQL 2008 you may want to look at the new Merge command.

MS Link:- http://technet.microsoft.com/en-us/library/bb510625.aspx


As per their site (technet.microsoft.com):-
Performs insert, update, or delete operations on a target table based on the results of a join with a source table. For example, you can synchronize two tables by inserting, updating, or deleting rows in one table based on differences found in the other table.

Hope that helps...though the other answers are also very good. :)

Cheers,

Steve


取决于您的数据库提供程序,您可以让数据库处理它.

SQL Server 2008+:合并(感谢史蒂夫已经找到此链接)
MySQL:插入...在重复键更新上...
Depending your database provider, you can let the database deal with it.

SQL Server 2008+: MERGE (thanks Steve for finding this link already)
MySQL: INSERT ... ON DUPLICATE KEY UPDATE ...


尝试使用命令生成器
http://msdn.microsoft.com/en-us/library/tf579hcz.aspx [ ^ ]
Try using Command builder
http://msdn.microsoft.com/en-us/library/tf579hcz.aspx[^]


这篇关于如果记录存在,请对其进行更新.如果没有,请插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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