首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Access >

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

2012-02-17 
Insert into 不能where,哪怎么判断呢?我想向表插入一条记录,但如果表已经存在此记录,就不插入,不知如何实

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'

热点排行