如何删除不满足条件的记录?

wangxiao2008 2008-04-16 01:42:07
把库1中的记录删除
条件:库1.dbo.表1.字段<>库2.dbo.表2.字段
下面代码说"无法绑定由多个部分组成的标识符库2.dbo.表2.字段"
delete
from 库1.dbo.表1
where (库1.dbo.表1.字段<>库2.dbo.表2.字段)


...全文
146 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhu_gx 2008-04-16
  • 打赏
  • 举报
回复
低调拼小命接分,帮你顶。。。
hqq01025 2008-04-16
  • 打赏
  • 举报
回复
听说exists的效率比in要高点,具体我没有测试过
hqq01025 2008-04-16
  • 打赏
  • 举报
回复

delete from 库1.dbo.表1 a
where not exists(
select *
from 库2.dbo.表2 b
where a.field1 = b.field1)
Limpire 2008-04-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wangxiao2008 的回复:]
delete 库1.dbo.表1
from 库1.dbo.表1 ,库2.dbo.表2
where (库1.dbo.表1.字段 <>库2.dbo.表2.字段)

怎摸数据库中的记录都没了?

[/Quote]
这样删肯定都没了

delete from 库1.dbo.表1
where 库1.dbo.表1.字段 not in (select 字段 from 库2.dbo.表2.字段)
zccmy22 2008-04-16
  • 打赏
  • 举报
回复
左链接
wangxiao2008 2008-04-16
  • 打赏
  • 举报
回复
from 库1.dbo.表1 a left out join 库2.dbo.表2 b on a.字段=b.字段
看不太懂
littleflowerfox 2008-04-16
  • 打赏
  • 举报
回复
delete
from 库1.dbo.表1
where 库1.dbo.表1.字段 not in (select 库2.dbo.表2.字段 from 库2.dbo.表2)
liangCK 2008-04-16
  • 打赏
  • 举报
回复
delete a
from 库1.dbo.表1 a left out join 库2.dbo.表2 b on a.字段=b.字段
where b.字段 is null
liangCK 2008-04-16
  • 打赏
  • 举报
回复
where (库1.dbo.表1.字段 <>库2.dbo.表2.字段)
看懂这个很重要。
wangxiao2008 2008-04-16
  • 打赏
  • 举报
回复
delete 库1.dbo.表1
from 库1.dbo.表1 ,库2.dbo.表2
where (库1.dbo.表1.字段 <>库2.dbo.表2.字段)

怎摸数据库中的记录都没了?
liangCK 2008-04-16
  • 打赏
  • 举报
回复
delete a
from 库1.dbo.表1 a,库2.dbo.表2 b
where a.字段<>b.字段
liangCK 2008-04-16
  • 打赏
  • 举报
回复
delete哪个

34,575

社区成员

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

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