sql server编写通用脚本自动检查两个不同服务器的新旧数据库的表结构差异
时 间:2019-07-19 08:52:20
作 者:缪炜 ID:24010 城市:江阴
摘 要:工作过程中,不管是什么项目,伴随着项目不断升级版本,对应的项目数据库业务版本也不断升级,数据库出现新增表、修改表、删除表、新增字段、修改字段、删除字段等变化,如果人工检查,数据库表和字段比较多的话,工作量就非常大。
正 文:
-- 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
Access软件网QQ交流群 (群号:483923997) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access两种方式实现即时更...(03.01)
- Access隐藏与显示lacc...(01.12)
- 【Access高效办公】将每个...(12.23)
- Access21点游戏源代码(12.13)
- 【Access窗体导出Exce...(11.15)
- 【Access开发】Acces...(11.14)
- 通过Access宏录入数据到选...(11.10)
- 用DLOOKUP函数将需求表中...(10.31)
- Access日期区间段查询数据...(10.25)
学习心得
最新文章
- Access快速开发平台--在WI...(03.08)
- 使用SQL语句删除xscj表中学号...(03.08)
- Access快速开发平台进销存教程...(03.07)
- Access快速开发平台--frm...(03.06)
- 【Access删除查询】删除数字最...(03.06)
- Access快速开发平台进销存教程...(03.05)
- Access快速开发平台进销存教程...(03.04)
- Access快速开发平台--IsL...(03.02)
- Access两种方式实现即时更新月...(03.01)
- Access开发的资金管理系统;基...(02.29)