You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dsMin/RunQianUpdate/多年段数据库合并成一个的办法.txt

32 lines
1.8 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

要安装 SqlServer Management Studio 2012客户端不要使用Navicat Prenium !!!
------------------------------------------------------------------------------------
一、创建一个数据库Temp2020,并进入此库
use eduData2020DB_xt;
select 'select * into Temp2020.dbo.'+table_name+' from '+table_name as sql from information_schema.tables;
如果有个别视图无法创建,需要手工删除一些。
------------------------------------------------------------------------------------
二、 添加字段
use Temp2020;
select 'if not exists (select * from syscolumns where id=object_id('''+table_name+''') and name=''recordyear'') ALTER TABLE '+table_name+' ADD recordyear INT;' as sql from information_schema.tables;
------------------------------------------------------------------------------------
三、 更新年份
select 'update '+table_name+' set recordyear=2020;' as sql from information_schema.tables;
------------------------------------------------------------------------------------
四、以后有其它年份也是像上面一样的办法导入到Temp2019,Temp2018...中。 
------------------------------------------------------------------------------------
五、使用神器安装SQL Server 2012 R1,然后使用SQL Server 导入和导出向导以Temp2020为基底将Temp2019,Temp2018...逐个导入到Temp2020库中!
注:只保留以 [J,Z,G,V]+schoolBusinessRelation开头即可微软的东西人性化非常好可以反选还可以用Shift+多选+反选,一级棒!
------------------------------------------------------------------------------------
六、利用ESF将合并完的数据库Temp2020导入到PG数据库中。
------------------------------------------------------------------------------------
黄海 2022-09-01