xzh2000的博客 本人提供杭州地区Oracle现场技术支持服务,包括性能调整、DataGuard、RAC等。
01 12, 2006
用sql比较两个库是否一致
作者 xzh2000 15:43 | Permalink 静态链接网址 | Comments 最新回复 (0) | Trackback 引用 (0) | 技术交流

比较两个数据库,可以用工具,比如toad等,也可以自己写存储过程来实现,偶介绍一个用sql来核对表结构是否一致,以此类推,大家可以写出对比索引是否一致,对比约束是否一致的sql,该sql的缺点就是只能查出差异,却不知是那个表引起的:


select case when a.cnt = b.cnt then '两个库结构一致'
when a.cnt <> b.cnt then '两个库结构不一致' end
from (select count(*) as cnt
from dba_tab_columns t1, dba_tab_columns@lnk_db2 t2
where t1.owner = 'TAOBAO'
and t1.owner = t2.owner
and t1.table_name = t2.table_name
and t1.column_name = t2.column_name
and t1.data_type = t2.data_type
and t1.data_length = t2.data_length
and t1.nullable = t2.nullable
and nvl(t1.data_precision, 0) = nvl(t2.data_precision, 0)
and nvl(t1.data_scale, 0) = nvl(t2.data_scale, 0)) a,
(select count(*) as cnt
from dba_tab_columns
where owner = 'TAOBAO') b

Comments
博客日历
« 七月 2009 »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
搜索
最新发表
文章分类
文章归档
网站链接
新闻聚合