Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Mon, 17 Dec 2007 @ 16:56:47 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Verifying tables structures between two different databases
 
From:   Dieter Noeth

Suresh Koppusetty wrote:

          > Select databasename, tablename
          >     From dbc.TABLES
          >     Where databasename = 'db_a'
          >     Minus
          >     Select Databasename, tablename
          >     From dbc.TABLES
          >     Where databasename = 'db_b'
  uses "MINUS"" function, to get the difference of tables between 2 databases.  


  But is there anyway without using minus function, can we get the output.  


The easiest way is a Full Outer Join like this:

     Select
        coalesce(a.databasename, b.databasename),
        coalesce(a.tablename, b.tablename),
        case
          when a.tablename is null then 'table missing in database a'
          when b.tablename is null then 'table missing in database b'
          else 'table match'
        end
     from
     (select * from dbc.TABLES
       Where databasename = 'db_a')  as a
     full outer join
     (select * from dbc.TABLES
       Where databasename = 'db_b')  as b
     on
        a.databasename = b.databasename
     and
        a.tablename = b.tablename
     where
         a.tablename is null
     or b.tablename is null

This can be easily enhanced for missing columns, different datatypes, formats, defaults...

e.g

     case
        ....
        when a.ProtectionType <> b.ProtectionType then 'missmatch: protection
     types'
     end
     ...
     where
     ...
     or a.ProtectionType <> b.ProtectionType

Dieter



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023