免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 6636 | 回复: 15
打印 上一主题 下一主题

如何判断2表是否完全相同? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-08-12 15:11 |只看该作者 |倒序浏览

论坛徽章:
0
2 [报告]
发表于 2004-08-12 22:16 |只看该作者
应该是都要,我猜他这样想的,如果是的法要怎么做

论坛徽章:
0
3 [报告]
发表于 2004-08-13 08:27 |只看该作者
都要的,呵呵。其实我只是想看看用不同方法得出的两张表是否完全一致。:lovely:

论坛徽章:
0
4 [报告]
发表于 2004-08-13 09:38 |只看该作者
有没有简单点的方法告诉小弟啊:try:

论坛徽章:
0
5 [报告]
发表于 2004-08-13 12:35 |只看该作者
在数据库里面不是很好做,先用导入导出工具导成txt文件,然后用ultraEdit比较

论坛徽章:
0
6 [报告]
发表于 2004-08-13 12:51 |只看该作者
sql server 有没有oracle的minus语句? 呵呵
oracle里面:
select count(*) from
(select * from a
minus
select * from b)

论坛徽章:
0
7 [报告]
发表于 2004-08-13 13:12 |只看该作者
表结构就不用比了吧?

1> select * into t0 from t
2> go
(7 行受到影响)
1> begin transaction
2> declare @num_a int
3> declare @num_b int
4> declare @num_c int
5> select @num_a=count(*) from t
6> select @num_b=count(*) from t0
7> select @num_c=count(*) from t,t0 where t.a=t0.a and t.b=t0.b   -- a.col1=b.col1 and a.col2=b.col2....
8> if (@num_a=@num_b and @num_b=@num_c)
9>  print \'table a == table b\'
10> else print \'table a =\\= table b\'
11> commit transaction
12> go
table a == table b

1> insert into t0(b) values(1)
2> go
(1 行受到影响)
1> begin transaction
2> declare @num_a int
3> declare @num_b int
4> declare @num_c int
5> select @num_a=count(*) from t
6> select @num_b=count(*) from t0
7> select @num_c=count(*) from t,t0 where t.a=t0.a and t.b=t0.b
8> if (@num_a=@num_b and @num_b=@num_c)
9>  print \'table a == table b\'
10> else print \'table a =\\= table b\'
11> commit transaction
12> go
table a =\\= table b

论坛徽章:
0
8 [报告]
发表于 2004-08-13 13:13 |只看该作者
大表就不要拿出来比了~ /

论坛徽章:
0
9 [报告]
发表于 2004-08-13 15:10 |只看该作者
谢谢!
问题解决了,
我用selelct * from a join b on a. 所有字段=b.所有字段
如果行数没变就相等,笨办法,别见笑,呵呵
winkexp兄弟的算法看起来好复杂,没验证,不过真的很感谢!:rose:

论坛徽章:
0
10 [报告]
发表于 2004-08-13 15:21 |只看该作者
我是初学的不要见笑:我认为你的方法有一个缺点,会改变数据库。在不改变数据库内容的条件下是不行的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP