查询插入新行如果不存在则不执行任何操作 [英] query to insert new row if does not exists else do nothing

查看:100
本文介绍了查询插入新行如果不存在则不执行任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用控制台应用程序,我希望在表中插入数据,但是如果数据已经存在而不执行任何操作。

我的表名是统计信息,列是msg_id。如果表中已经存在msg_id而不是其他任何插入。

I am having console app from which I want to insert data in table but if the data already exists than do nothing.
My table name is statistics and column is msg_id. If the msg_id is already present in table than do nothing else insert.

推荐答案

检查此URL



MySQL:如果表中不存在则插入记录 [ ^ ]
Check this url

MySQL: Insert record if not exists in table[^]


if exists (select *From statistics where msg_id='')
begin
print 'exists' 
end
else 
begin
insert query
end


这篇关于查询插入新行如果不存在则不执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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