电脑桌面
添加蚂蚁七词文库到电脑桌面
安装后可以在桌面快捷访问

数据库迁移——星空oracle转sql server对象迁移完整性比较

来源:金蝶云社区作者:金蝶2024-09-161

数据库迁移——星空oracle转sql server对象迁移完整性比较

1、oracle数据库统计表的数据量(oracle库执行)

--DROP TABLE chl_tablerecord
create table chl_tablerecord(ftablename varchar(300),fcount int,fcolumn_count int,fkeycount int);
insert into  chl_tablerecord(ftablename,fcolumn_count)
select a.table_name,b.fcount from user_tables a join (select table_name,count(1) fcount from user_tab_cols group by table_name) b on a.table_name=b.table_name
where a.table_name not  like 'TMP%' and a.table_name not like 'TM%'  and a.table_name not like 'MLOG%'    and a.table_name not like '%$%'  
and a.table_name not in ( select object_name from user_objects where object_type='MATERIALIZED VIEW'  );
COMMIT;
/
--统计数据量
declare 
var_ftablename varchar2(300);
cursor chl_cur is select  ftablename from chl_tablerecord;
begin
open chl_cur;
fetch chl_cur into var_ftablename;
while chl_cur%found loop  --使用游标属性
execute immediate 'update chl_tablerecord set fcount=(select count(1) from '||var_ftablename||') where ftablename='''||var_ftablename||'''' ;
fetch chl_cur into var_ftablename;
end loop;
close chl_cur;
end;
/
COMMIT;

2、在迁移后sql server数据库比较迁移对象完整性

注意下面用到的[ORC]为sql server到oracle的连接服务器,具体配置参考:

https://wenku.my7c.com/article/243415848155361536

---星空数据中心oracle数据库迁移为sql server数据库,如何比较迁移前和迁移后的库
----------------------------------------------------------------------------表对比
if exists(select 1 from sys.tables where name like 'chl_tablerecord')
drop table chl_tablerecord
create table chl_tablerecord(ftablename varchar(300),fcount int,fcolumn_count int,fkeycount int)
go
insert into chl_tablerecord(ftablename,fcolumn_count)
select name,b.fcolumn_count from sys.tables a join (select object_id,count(1)  fcolumn_count from sys.columns group by object_id) b  on a.object_id=b.object_id
where name not like 'z/_%' escape '/' and name not like 'tmp%'
update chl_tablerecord set fkeycount=0
update a set a.fkeycount=b.fcount from chl_tablerecord a join (select TABLE_NAME, CONSTRAINT_NAME,count(1) fcount from  INFORMATION_SCHEMA.KEY_COLUMN_USAGE group by TABLE_NAME, CONSTRAINT_NAME) b 
on a.ftablename=b.TABLE_NAME 
go
--查询oracle的表在迁移后的sql server库不存在
if exists(select 1 from sys.tables where name like 'chl_tablenotexists')
drop table chl_tablenotexists
select  * into chl_tablenotexists  from openquery([ORC],'select * from chl_tablerecord') 
where ftablename not in (select ftablename from  chl_tablerecord);
--请确认查询出来的表是否不需要的表
select * from chl_tablenotexists
----------------------------------------------------------------------------主键对比
if exists(select 1 from sys.tables where name like 'chl_primaryotexists')
drop table chl_primaryotexists
select  a.*,b.fkeycount fkeycount_mssql into chl_primaryotexists  from openquery([ORC],'select * from chl_tablerecord') a  join chl_tablerecord b on a.ftablename=b.ftablename
where a.fkeycount<>b.fkeycount
--查询oracle的主键在sql server不存在
select * from chl_primaryotexists

----------------------------------------------------------------------------列对比
if exists(select 1 from sys.tables where name like 'chl_tablecolnotexists')
drop table chl_tablecolnotexists
select t1.* into chl_tablecolnotexists  from  openquery([ORC],'select table_name,column_name from user_tab_cols where table_name in (select ftablename from chl_tablerecord  ) and column_name not like ''SYS_NC%''') t1
left join (select b.ftablename table_name,a.name column_name from  sys.columns  a join chl_tablerecord b on a.object_id=object_id(b.ftablename)  ) t2
on t1.table_name=t2.table_name and t1.column_name=t2.column_name
where t1.table_name not in (select ftablename from chl_tablenotexists) and t2.table_name is null
--查询oracle的列在迁移后的sql server 数据库不存在
select * from chl_tablecolnotexists
---------------------------------------------------------------------------数据量对比
--sql server统计表数据量
declare @ftablename varchar(300)
declare  chl_cur cursor for
select  ftablename from chl_tablerecord
open chl_cur
fetch chl_cur into @ftablename
while(@@FETCH_STATUS<>-1)
begin
exec('update chl_tablerecord set fcount=(select count(1) from '+@ftablename+') where ftablename='''

数据库迁移——星空oracle转sql server对象迁移完整性比较

1、oracle数据库统计表的数据量(oracle库执行)--DROP TABLE chl_tablerecordcreate table chl_tablerecord(ftablename varchar(300),fcou...
点击下载文档文档为doc格式

声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

已经是第一篇
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息
QQ群
  • 答案:my7c点击这里加入QQ群
支持邮箱
微信
  • 微信