| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Compare (diff) Oracle DB and MS-SQLServer DB - DBArtisan
This is not mine -- I just added the SYNONYMS
The remote link (for the database to compare to) is @IHP (global edit as
needed)
/*
This script compares the object definitions in the current schema
to that of a remote schema.
The remote schema is defined using a database link.
THE SCRIPT COMPARES THE FOLLOWING:
- Existence of tables - Existence of columns - Column definitions - Existence of indexes - Index definitions (column usage) - Existence of constraints - Constraint definitions (table, type and reference) - Constraint column usage (for unique, primary key and foreign keys) - Check constraint definitions - Existence of triggers - Definition of triggers - Existence of procedure/packages/functions - Definition of procedures/packages/functions(Ie. the script does not do a complete check, it does not for example check any grants, clusters or storage definitions). The script drops and creates a few temporary objects prefixed with the first 3 letter combination (AAA - ZZZ) that does not conflict with any existing objects.
i number ; j number ; k number ;
select count(*) into cnt from DBA_objects_at_IHP where object_name like
chr(i)||chr(j)||chr(k)||'%'
AND OWNER = upper('&&1');
if cnt = 0 then
:prefx := chr(i)||chr(j)||chr(k);
return;
end if;
spool c:\project\listings\&&1.dbdiff.lst
PROMPT
PROMPT
PROMPT
create table &prex.diff_cols1
( TABLE_NAME VARCHAR2(30), COLUMN_NAME VARCHAR2(30), DATA_TYPE VARCHAR2(9), DATA_LENGTH NUMBER, DATA_PRECISION NUMBER, DATA_SCALE NUMBER, NULLABLE VARCHAR2(1), COLUMN_ID NUMBER, DEFAULT_LENGTH NUMBER, DATA_DEFAULT varchar2(2000)); create table &prex.diff_cols2 ( TABLE_NAME VARCHAR2(30), COLUMN_NAME VARCHAR2(30), DATA_TYPE VARCHAR2(9), DATA_LENGTH NUMBER, DATA_PRECISION NUMBER, DATA_SCALE NUMBER, NULLABLE VARCHAR2(1), COLUMN_ID NUMBER, DEFAULT_LENGTH NUMBER, DATA_DEFAULT varchar2(2000));declare
l.TABLE_NAME , l.COLUMN_NAME, l.DATA_TYPE , l.DATA_LENGTH, l.DATA_PRECISION , l.DATA_SCALE , l.NULLABLE, l.COLUMN_ID , l.DEFAULT_LENGTH , l.DATA_DEFAULT
TABLE_NAME VARCHAR2(30), COLUMN_NAME VARCHAR2(30), DATA_TYPE VARCHAR2(9), DATA_LENGTH NUMBER, DATA_PRECISION NUMBER, DATA_SCALE NUMBER, NULLABLE VARCHAR2(1), COLUMN_ID NUMBER, DEFAULT_LENGTH NUMBER, DATA_DEFAULT varchar2(2000));
(c.table_name,c.column_name,c.data_type,c.data_length,
c.DATA_PRECISION, c.DATA_SCALE, c.NULLABLE, c.COLUMN_ID,
c.DEFAULT_LENGTH, c.DATA_DEFAULT);
l.TABLE_NAME , l.COLUMN_NAME, l.DATA_TYPE , l.DATA_LENGTH, l.DATA_PRECISION , l.DATA_SCALE , l.NULLABLE, l.COLUMN_ID , l.DEFAULT_LENGTH , l.DATA_DEFAULT
TABLE_NAME VARCHAR2(30), COLUMN_NAME VARCHAR2(30), DATA_TYPE VARCHAR2(9), DATA_LENGTH NUMBER, DATA_PRECISION NUMBER, DATA_SCALE NUMBER, NULLABLE VARCHAR2(1), COLUMN_ID NUMBER, DEFAULT_LENGTH NUMBER, DATA_DEFAULT varchar2(2000));
(c.table_name,c.column_name,c.data_type,c.data_length,
c.DATA_PRECISION, c.DATA_SCALE, c.NULLABLE, c.COLUMN_ID,
c.DEFAULT_LENGTH, c.DATA_DEFAULT);
l.column_name=r.column_name and l.DATA_DEFAULT != r.DATA_DEFAULT
union
select l.table_name,l.column_name,'DATA_TYPE',l.data_type,r.data_type
from &prex.diff_cols1 l, &prex.diff_cols2 r
where l.table_name=r.table_name and
l.column_name=r.column_name and l.data_type != r.data_type
union
select l.table_name,l.column_name,'DATA_LENGTH',to_char(l.data_length),
to_char(r.data_length)
from &prex.diff_cols1 l, &prex.diff_cols2 r
where l.table_name=r.table_name and
l.column_name=r.column_name and l.data_length != r.data_length
union
select l.table_name,l.column_name,'DATA_PRECISION',
to_char(l.DATA_PRECISION),to_char(r.DATA_PRECISION)
from &prex.diff_cols1 l, &prex.diff_cols2 r
where l.table_name=r.table_name and
l.column_name=r.column_name and l.DATA_PRECISION != r.DATA_PRECISION
union
select l.table_name,l.column_name,'DATA_SCALE',to_char(l.DATA_SCALE),
to_char(r.DATA_SCALE)
from &prex.diff_cols1 l, &prex.diff_cols2 r
where l.table_name=r.table_name and
l.column_name=r.column_name and l.DATA_SCALE != r.DATA_SCALE
union
select l.table_name,l.column_name,'NULLABLE',l.NULLABLE,r.NULLABLE
from &prex.diff_cols1 l, &prex.diff_cols2 r
where l.table_name=r.table_name and
l.column_name=r.column_name and l.NULLABLE != r.NULLABLE
union
select l.table_name,l.column_name,'COLUMN_ID',to_char(l.COLUMN_ID),
to_char(r.COLUMN_ID)
from &prex.diff_cols1 l, &prex.diff_cols2 r
where l.table_name=r.table_name and
l.column_name=r.column_name and l.COLUMN_ID != r.COLUMN_ID
union
select
l.table_name,l.column_name,'DEFAULT_LENGTH',to_char(l.DEFAULT_LENGTH),
to_char(r.DEFAULT_LENGTH)
from &prex.diff_cols1 l, &prex.diff_cols2 r
where l.table_name=r.table_name and
l.column_name=r.column_name and l.DEFAULT_LENGTH != r.DEFAULT_LENGTH
order by 1,2
/
create table &prex.common_indexes as
select table_name, index_name from DBA_indexes_at_EID1
where table_name in (select table_name from &prex.common_tables) AND OWNER
= upper('&&1')
intersect
select table_name, INdex_name from DBA_indexes_at_IHP
where table_name in (select table_name from &prex.common_tables) AND OWNER
= upper('&&1');
PROMPT
PROMPT
PROMPT
DBA_indexes_at_EID1 b
where a.index_name = b.index_name
and a.uniqueness != b.uniqueness
and (a.table_name, a.index_name) in
(select table_name, index_name from &prex.common_indexes)
AND B.OWNER = upper('&&1')
AND A.OWNER = upper('&&1');
PROMPT
PROMPT
PROMPT
b.column_position IHP
from DBA_ind_columns_at_IHP a,
DBA_ind_columns_at_EID1 b
where (a.table_name,a.index_name) in
and b.index_name = a.index_name
and b.table_name = a.table_name
and a.column_name = b.column_name
and a.column_position != b.column_position
AND B.INDEX_OWNER = upper('&&1')
AND A.INDEX_OWNER = upper('&&1');
PROMPT
PROMPT
PROMPT
a.table_name = b.table_name and a.constraint_name=b.constraint_name and a.constraint_type !=b.constraint_type
and a.table_name != b.table_name
AND B.OWNER = upper('&&1')
AND A.OWNER = upper('&&1');
from DBA_cons_columns_at_IHP a, &prex.comcons b
where a.constraint_name=b.constraint_name
AND OWNER = upper('&&1')
intersect
select a.constraint_name,a.position,a.column_name,b.constraint_type
from DBA_cons_columns_at_EID1 a, &prex.comcons b
where a.constraint_name=b.constraint_name
AND A.OWNER = upper('&&1')
);
i binary_integer;
begin
for c in c1 loop
dbms_output.put_line('COLUMN USAGE DIFFERENCE FOR '||c.constraint_type||
' CONSTRAINT '||c.constraint_name);
dbms_output.put_line('. Local columns:');
i:=1;
for c2 in (select column_name col
from DBA_cons_columns_at_IHP
where constraint_name=c.constraint_name AND OWNER = upper('
&&1') order by position)
loop
dbms_output.put_line('. '||c2.col);
end loop;
i:=1;
dbms_output.put_line('. Remote columns:');
for c3 in (select column_name col
from DBA_cons_columns_at_EID1
where constraint_name=c.constraint_name AND OWNER = upper('
&&1')
)
loop
dbms_output.put_line('. '||c3.col);
end loop;
cons varchar2(50); tab1 varchar2(50); tab2 varchar2(50);
dbms_output.put_line('Check constraint '||c.constraint_name||
' defined differently!');
dbms_output.put_line('. EID definition:');
dbms_output.put_line('. '||search1);
dbms_output.put_line('. IHP definition:');
dbms_output.put_line('. '||search2);
end if;
desc1 varchar2(2000); body1 varchar2(32000); type2 varchar2(16);
-------------------------------------------------'||
'-----------------------');
pr_head := TRUE;
dbms_output.put_line(' ');
dbms_output.put_line('DEFINED ON DIFFERENT TABLES!');
dbms_output.put_line('. EID table_name : '||table1);
dbms_output.put_line('. IHP table_name: '||table2);
end if;
dbms_output.put_line('T R I G G E R : '||nam1);
dbms_output.put_line('
-------------------------------------------------'||
'-----------------------');
pr_head := TRUE;
dbms_output.put_line(' ');
dbms_output.put_line('DEFINED FOR DIFFERENT EVENTS!');
dbms_output.put_line('. EID event: '||event1);
dbms_output.put_line('. IHP event: '||event2);
end if;
dbms_output.put_line('T R I G G E R : '||nam1);
dbms_output.put_line('
-------------------------------------------------'||
'-----------------------');
pr_head := TRUE;
dbms_output.put_line(' ');
dbms_output.put_line('DIFFERENT TYPES!');
dbms_output.put_line('. EID type: '||type1);
dbms_output.put_line('. IHP type: '||type2);
end if;
dbms_output.put_line('T R I G G E R : '||nam1);
dbms_output.put_line('
-------------------------------------------------'||
'-----------------------');
pr_head := TRUE;
dbms_output.put_line(' ');
dbms_output.put_line('DIFFERENT REFERENCES!');
dbms_output.put_line('. EID ref: '||ref1);
dbms_output.put_line('. IHP ref: '||ref2);
end if;
dbms_output.put_line('T R I G G E R : '||nam1);
dbms_output.put_line('
-------------------------------------------------'||
'-----------------------');
pr_head := TRUE;
dbms_output.put_line('DIFFERENT WHEN CLAUSES!');
dbms_output.put_line('. EID when_clause:');
dbms_output.put_line(when1);
dbms_output.put_line('. IHP when_clause: ');
dbms_output.put_line(when2);
dbms_output.put_line(' ');
dbms_output.put_line('DIFFERENT STATUS!');
dbms_output.put_line('. EID status: '||status1);
dbms_output.put_line('. IHP status: '||status2);
end if;
dbms_output.put_line(' ');
dbms_output.put_line('DIFFERENT DESCRIPTIONS!');
dbms_output.put_line('EID definition: ');
dbms_output.put_line(desc1);
dbms_output.put_line('IHP definition: ');
dbms_output.put_line(desc2);
dbms_output.put_line(' ');
dbms_output.put_line('THE PL/SQL BLOCKS ARE DIFFERENT! ');
dbms_output.put_line(' ');
from DBA_source_at_IHP a, &prex.comcod b
where a.name=b.name AND OWNER = upper('&&1') union
select a.name,a.type,a.line,a.text
from DBA_source_at_EID1 a, &prex.comcod b
where a.name=b.name
AND A.OWNER = upper('&&1')
minus
(select a.name,a.type,a.line,a.text
from DBA_source_at_IHP a, &prex.comcod b
where a.name=b.name AND OWNER = upper('&&1')
intersect
select a.name,a.type,a.line,a.text
from DBA_source_at_EID1 a, &prex.comcod b
where a.name=b.name
AND OWNER = upper('&&1'))) q;
PROMPT
PROMPT
PROMPT
from DBA_Views_at_IHP where view_name=c.view_name AND OWNER = upper
('&&1');
select text,text_length into def2,len2
from DBA_Views_at_EID1 where view_name=c.view_name AND OWNER = upper(' &&1');
i := 1;
def1:=replace(def1,' ','');
def2:=replace(def2,' ','');
if def1 != def2 or length(def1) != length(def2) then
dbms_output.put_line(lpad('-',35+length(c.view_name),'-'));
dbms_output.put_line('| '||c.view_name ||
' |');
dbms_output.put_line(lpad('-',35+length(c.view_name),'-'));
dbms_output.put_line('EID text_length: ' || to_char(len1));
dbms_output.put_line('IHP text_length): ' || to_char(len2));
dbms_output.put_line(' ');
i := 1;
while i <= length(def1) loop
if substr(def1,i,240) != substr(def2,i,240) then
dbms_output.put_line('Difference at offset ' ||
to_char(i)
dbms_output.put_line(' EID: ' ||
substr(def1,i,240));
dbms_output.put_line(' IHP: ' ||
substr(def2,i,240));
end if;
i := i + 240;
dbms_output.put_line('IHP longer than EID. Next 255 bytes: ');
dbms_output.put_line(substr(def2,length(def1),255));
end if;
prompt ************** END of REPORT ************************spool off
drop table &prex.comcod; drop table &prex.diff_cols1; drop table &prex.diff_cols2; drop table &prex.common_tables; drop table &prex.common_views; drop table &prex.common_indexes; drop table &prex.common_synonyms; drop table &prex.comcons;
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Thomas Day INET: tday6_at_csc.com Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Fri Apr 26 2002 - 15:30:30 CDT
![]() |
![]() |