• 站点地图
  • 加入收藏
  • 设为首页
  • 中国网管、站长学习园地hspace="5"
    当前位置:IT加速度>>数据库>>Mssql>>内容阅读
    用sql比较两个数据库是否一致
    作者:  来源:  时间:2008-07-24
      导读:

     
    比较两个数据库,可以用工具,比如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

    责任编辑:it415.com

    上一篇:50种方法巧妙优化你的SQL Server数据库
    下一篇:教你如何编写高效的MySQL数据库应用
    相关内容