如何判断一条记录在数据库中是否存在

kunta0514 2008-01-28 03:31:45
比如我有一个表A 字段有A_1,就把他看成只有一个字段把。。。
我现在要添加一行数据,xx
如何判断表A中存在同样的数据

...全文
655 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
屮艸芔茻2014 2010-12-07
  • 打赏
  • 举报
回复
学到就mark
netcellsoft 2008-01-28
  • 打赏
  • 举报
回复
declare @name char
if not exists(select * from tableName where colname=@name)
begin
insert into tab(a1) select id from a
end
else
begin
print 'can not add'
end
netcellsoft 2008-01-28
  • 打赏
  • 举报
回复
if not exists(select * from tableName where colname=@name)
begin
insert into tab(..) select ...
end
else
print "can not add"
end if
liangCK 2008-01-28
  • 打赏
  • 举报
回复
if not exists(select 1 from t1 where id=2) 
insert into t1 values(xx)
ojuju10 2008-01-28
  • 打赏
  • 举报
回复


if not exists(select * from tableName where colname=@name)
begin
insert into tab(..) select ...
end
pengxuan 2008-01-28
  • 打赏
  • 举报
回复

if exists(select 1 from t1 where id='2')
print '不能添加'
kunta0514 2008-01-28
  • 打赏
  • 举报
回复
如果存在。。

不能添加。。。

这改怎么写啊。。。
feng2112 2008-01-28
  • 打赏
  • 举报
回复
楼上正解
--不存在
if not exists(select * from tableName)
begin
print 1
end
pt1314917 2008-01-28
  • 打赏
  • 举报
回复

--如果存在
if exists(select 1 from A where A_1='XX')
begin

end

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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