专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Access

Insert into 不能where,哪如何判断呢

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
Insert into 不能where,哪怎么判断呢?
我想向表插入一条记录,但如果表已经存在此记录,就不插入,不知如何实现?



insert into tb(Bh) values('001');

如果表里存在Bh=001的记录,就不插入,不知如何做到这点?

我现在是先判断select * from tb where Bh<>'001'
后再执行inser into语句,

觉得有点麻烦,不知能不能用一句SQL来实现?谢谢

------解决方案--------------------
虽然是一句SQL,但效率很差。

SQL code
insert into tb(Bh) 
select top 1 '001' from tb where not exists (select 1 from tb where bh='001')

------解决方案--------------------
我还就没想出来
------解决方案--------------------
insert into tb(Bh) select distinct '001' from tb where Bh<>'001'
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: