如何判断两张表的记录完全相同呢,谢谢?

jjgaodeng 2003-10-21 08:54:23
例如 表1
id 自动编号
djh 单据号
sl 数量

表2
id 自动编号
djh 单据号
memo 备注

如何才能判断两张表中记录完全相同,如不同,是那几个记录不同,,
这个过程应该怎么写呢??谢谢
...全文
60 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
axiaowin 2003-10-21
  • 打赏
  • 举报
回复
a.memo,表1没有memo字段
dafu71 2003-10-21
  • 打赏
  • 举报
回复
表1有,表2无
select * from 表1 where not exists(select 1 from 表2 where
表1.djh=表2.djh)

表2有,表1无
select * from 表2 where not exists(select 1 from 表1 where
表1.djh=表2.djh)

axiaowin 2003-10-21
  • 打赏
  • 举报
回复
select * from 表1 where djh not in (select djh from 表2)

select * from 表2 where djh not in (select djh from 表1)

只判断了单据号,能判断两条记录完全相等吗?Table1.djh <> Table2.djh,那不就是不相等了,最少两条记录的djh字段不相等
txlicenhe 2003-10-21
  • 打赏
  • 举报
回复
Select * from 表1 a full join 表2 b on a.id = b.id
where a.id is null or b.id is null
or a.djh is null or b.djh is null
or a.memo is null or b.memo is null
pengdali 2003-10-21
  • 打赏
  • 举报
回复
select * from 表1 where djh not in (select djh from 表2)

select * from 表2 where djh not in (select djh from 表1)

34,576

社区成员

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

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