zoukankan      html  css  js  c++  java
  • Sql 2005 中比较两个数据库差异

    构建两个临时表,将两个数据库结构信息导入。

    create Table #t1
    (
     ID Int Identity(1,1) Not Null Primary Key,
     tablename nvarchar(50)  NULL,
     columnName nvarchar(50)  NULL,
     columnIndex int null,
     columnType nvarchar(50)  NULL
    )

    use 数据库1

    insert into #t1

    create Table #t2
    (
     ID Int Identity(1,1) Not Null Primary Key,
     tablename nvarchar(50)  NULL,
     columnName nvarchar(50)  NULL,
     columnIndex int null,
     columnType nvarchar(50)  NULL
    )

    //开始比较

    use 数据库2

    insert into #t2
    SELECT    
          SO.name as '表名',
          SC.name  as '表列名',
          SC.colid as '索引',
          ST.name as '类型'
      FROM      
          sysobjects   SO, -- 对象表
          syscolumns   SC, -- 列名表
          systypes     ST  -- 数据类型表
    WHERE        
         SO.id = SC.id
       AND   SO.xtype = 'U'    -- 类型U表示表,V表示视图
       AND   SO.status >= 0 --加一个条件:SO.status >= 0,否则会将系统的临时表显示出来
       AND   SC.xtype = ST.xusertype
    ORDER BY  
         SO.name, SC.colorder

    go

    //查询出 在t1 里有, t2 里没有的字段,查询列出来。

    select * from
       (
        select tablename,columnName,columnType from #t1 where tablename like '%EMS_%'
        EXCEPT
        select tablename,columnName,columnType from #t2 where tablename like '%EMS_%'
       ) as c
    order by tablename

  • 相关阅读:
    Asp.Net+Oracle+BootStrap+Jquery
    UML类图几种关系的总结
    PHP对象在内存堆栈中的分配
    php sprintf 详解
    微信错误代码45047:客服消息只能发送20条/个用户
    php利用array_search与array_column实现二维数组查找
    mvc 详解
    php中++i 与 i++ 的区分详解
    Git 别名多个命令 超实用
    php 对象继承
  • 原文地址:https://www.cnblogs.com/shanpeng/p/2341608.html
Copyright © 2011-2022 走看看