如果表中不存在新记录,如何在表中插入新记录?(SQL Server 2005) [英] how to insert new record in my table if this record not exists in my table?(sql server 2005)

查看:94
本文介绍了如果表中不存在新记录,如何在表中插入新记录?(SQL Server 2005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
如果此记录在表中不存在,我想在表中插入新记录
例如,当我编写此查询时

Hi All
I want insert new record in my table if this record not exists in my table
when i write this query for example

insert into tablename (code) values (''1448523'')
WHERE not exists(select * from tablename where code=''1448523'')



我的查询有误

Incorrect syntax near the keyword ''WHERE''

当我再次使用时(如果不存在),我会报错,

现在,如何在我的记录中不存在记录的情况下编写插入查询.



I have error in my query

Incorrect syntax near the keyword ''WHERE''

When i use if not exists again i have error,

Now how to write insert query if not exists record in my record.

推荐答案

如果您使用Google搜索,则会发现更早的解决方案:http://sqlservercodebook.blogspot.com/2008/04/easy- sql-if-record-exists-update-it-if.html [
If you had Googled, you would have found a solution a lot earlier: http://sqlservercodebook.blogspot.com/2008/04/easy-sql-if-record-exists-update-it-if.html[^]


这篇关于如果表中不存在新记录,如何在表中插入新记录?(SQL Server 2005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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