SQL insert 前的判断问题

cszd1313 2010-06-12 09:57:03
请问下各位学长,insert前如何对数据库里的数据判断有无,没有才插入,应该如何写SQL,@ 和&是什么作用
谢谢大家了
...全文
48 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
teerhu 2010-06-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jwdream2008 的回复:]
SQL code
if not exists( select 1 from table1 where column1='条件')
Insert into table1 values( .............)
[/Quote]
支持
我一般也是這樣做的
SQLRun 2010-06-12
  • 打赏
  • 举报
回复
我最喜欢的做法是先Update,如果影响行数为0,那么就执行insert。
cszd1313 2010-06-12
  • 打赏
  • 举报
回复
。。。。。
jwdream2008 2010-06-12
  • 打赏
  • 举报
回复
if  not exists( select 1 from table1 where column1='条件')
Insert into table1 values( .............)
永生天地 2010-06-12
  • 打赏
  • 举报
回复
if not exists(select 1 from tb where id='新增数据的id')
insert tb values(.....)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧