Compare tables from two different databases in SQL Developer
Codemia Knowledge Hub ·
In Oracle SQL Developer, connect to both databases and run Tools → Database Diff to compare table structures. For the data itself, write MINUS and JOIN queries that show rows missing from one side or values that differ. Both are common during data migrations, schema changes, and consistency checks across distributed systems.
What makes cross-database comparison hard
- Differences in schema: tables can differ in columns, data types, and constraints.
- Data discrepancies: rows may be missing or altered between databases.
- Performance: large datasets need careful resource use.
- Connectivity: the two database systems may use different protocols.
Steps in SQL Developer
- Set up connections:
- Open SQL Developer and create connections to both the source and target databases.
- Make sure you have the required access permissions on both.
- Run Database Diff:
- Go to
Tools→Database Diff. - Select the source and target connections.
- Choose the schemas and objects to compare.
- Review the comparison:
- The diff shows differences in table structure, including columns, data types, constraints, and indexes.
- From the results you can generate scripts to synchronize them.
- Compare data with SQL queries:
- To find rows that exist on only one side, combine
MINUSin both directions:
- Synchronize:
- SQL Developer can generate scripts for schema differences.
- For data differences, write your own scripts to update, insert, or delete rows as needed.
Example: comparing an EMPLOYEES table
Take two databases, DB_SOURCE and DB_TARGET, each with an EMPLOYEES table keyed on EMP_ID. Use Database Diff for column differences, then queries for the data. A query in one Oracle database reaches a table in another through a database link, so run these in DB_SOURCE after creating a link to DB_TARGET:
Fixing the mismatches
Once you know what differs, insert the missing rows and update the mismatched ones. For example, to copy names from source to target where they differ:
Steps and tools at a glance
| Feature/Step | Description | Example/Tool Use |
| Setting Up Connections | Establish connections to source and target databases in SQL Developer. | SQL Developer GUI |
| Schema Comparison | Use Database Diff to compare tables' structures. | Tools → Database Diff |
| SQL Data Comparison | Execute SQL queries to identify data discrepancies. | MINUS and UNION ALL SQL operations |
| Data Synchronization | Auto-generate scripts or manually create SQL scripts for syncing data/schema changes. | Synchronization scripts |
Other checks before you compare
- Data type mappings: keep data types consistent across databases to avoid truncation or conversion problems.
- Network configuration: confirm firewall and security settings allow cross-database operations.
- Audit and logging: keep logs of comparisons and changes for auditing and rollback.
Related reading
- Compare two DataFrames and output their differences side-by-side
- Compare two objects' properties to find differences?
- Comparing scikit learn clusterings using a decision tree
- Comparing two NumPy arrays for equality, element-wise
- Compare two MySQL databases
- Comparison of full text search engine - Lucene, Sphinx, Postgresql, MySQL?
- Comparison-based ranking algorithm
- Complex dataset split - StratifiedGroupShuffleSplit
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.