在单个sql查询中添加和更新 [英] Add and Update in single sql query

查看:80
本文介绍了在单个sql查询中添加和更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3列数据库表,ID,部件,计数。

如果ID最初出现,那么我想更新该ID,否则我想在表格中添加新条目。

我该怎么做?

解决方案

看到这个..希望它会有所帮助



插入并更新一体查询-in-sql-server-2005 [ ^ ]


  as  
如果 存在选择 id 来自 table name < span class =code-keyword>其中 Id = @ Id)
开始
插入语句
结束
else
更新对帐单


I have database table with 3 columns, ID,Parts,Count.
If ID present initially then I want to update that ID else I want to add New entry to table.
How can I do that?

解决方案

See this..Hope it will help

insert-and-update-in-one-query-in-sql-server-2005[^]


as
If not exists(select id from table name where Id=@Id )
begin
 Insert statement
End
else
Update statement
end


这篇关于在单个sql查询中添加和更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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