如何使用存储过程在不使用If条件的情况下在表中插入数据 [英] How Do I Insert Data In Table Using Store Procedure Without Using If Condition

查看:76
本文介绍了如何使用存储过程在不使用If条件的情况下在表中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有三列A,B和CA是主键。我想在表中插入数据,将这三个cloumns作为参数存储proecedure。我想使用主键检查表中是否已存在数据(列A)。存在Col A然后更新数据,否则插入数据。我想在没有If和else条件的情况下执行此操作。如何编写存储过程?

Suppose I have three columns A,B and C.A is primary key.I want to insert data in table passing these three cloumns as parameter to store proecedure.I want to check that data is already exist in table using Primary key( column A).Ff Col A exist then update the data else insert data. I want to do this without If and else condition.How can we write the store procedure?

推荐答案

您可以使用MERGE语句,参见 https://msdn.microsoft.com/en-us/library/bb510625.aspx [ ^ ]
You can use the MERGE statement, see https://msdn.microsoft.com/en-us/library/bb510625.aspx[^]


这篇关于如何使用存储过程在不使用If条件的情况下在表中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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