zoukankan      html  css  js  c++  java
  • SQLServer数据库差异比较

    //https://www.cnblogs.com/Leo_wl/p/11069813.html

    /*
        使用说明:Old数据库为DB_V1,New数据库为[localhost].DB_V2。根据实际需要批量替换数据库名称
        脚本来源:https://www.cnblogs.com/zhang502219048/p/11028767.html
    */
    
    -- sysobjects插入临时表
    select s.name + '.' + t.name as TableName, t.* into #tempTA 
    from DB_V1.sys.tables t
    inner join DB_V1.sys.schemas s on s.schema_id = t.schema_id
    
    select s.name + '.' + t.name as TableName, t.* into #tempTB 
    from [localhost].DB_V2.sys.tables t
    inner join [localhost].DB_V2.sys.schemas s on s.schema_id = t.schema_id
    
    -- syscolumns插入临时表
    select * into #tempCA from DB_V1.dbo.syscolumns 
    select * into #tempCB from [localhost].DB_V2.dbo.syscolumns
    
    -- 第一个数据库表和字段 
    select b.TableName as 表名, a.name as 字段名, a.length as 长度, c.name as 类型
    into #tempA
    from #tempCA a
    inner join #tempTA b on b.object_id = a.id
    inner join systypes c on c.xusertype = a.xusertype
    order by b.name 
    -- 第二个数据库表和字段 
    select b.TableName as 表名, a.name as 字段名, a.length as 长度, c.name as 类型
    into #tempB
    from #tempCB a
    inner join #tempTB b on b.object_id = a.id
    inner join systypes c on c.xusertype = a.xusertype
    order by b.name
    
    --删掉的字段
    select * from    
    ( 
        select * from #tempA
        except
        select * from #tempB
    ) a;
    
    --增加的字段
    select * from    
    ( 
        select * from #tempB
        except
        select * from #tempA
    ) a;
    
    --select * from #tempA
    --select * from #tempB
    
    drop table #tempTA, #tempTB, #tempCA, #tempCB, #tempA, #tempB
  • 相关阅读:
    web中的懒加载
    数据库表的关系
    struts2的MVC模式
    servlet与tomcat的关系
    servlet解析
    解决Mac外接显示器字体模糊的问题
    insmod: ERROR: could not insert module dm-snapshot.ko: Unknown symbol in module
    linux ssh tunnel
    Permission denied (publickey,gssapi-keyex,gssapi-with-mic).错误的解决
    Best practices for a new Go developer
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/11596059.html
Copyright © 2011-2022 走看看