I am looking for an efficient way to compare data between an Oracle and SQL Server table. I have no control over the Oracle table and can only perform select queries. This table contains 30,000+ rows. Currently I create a data set from the Oracle table and then compare the data with a SQL Server table that I do maintain. In this case I am just checking for the presence of a student number in the SQL Server table. In cases where the number is not present, I insert it into the SQL Server table. This is, as you can imagine, horribly inefficient. Your suggestions and examples would be greatly appreciated.
Share
Create a Linked Server instance on SQL Server, using an account that has access on the Oracle instance.
Then, you can update the SQL Server table with the missing contents using:
There are NOT IN and LEFT JOIN/IS NULL alternatives — NOT IN and NOT EXISTS perform better than LEFT JOIN/IS NULL when the columns compared (in this case, student_number) is not nullable (the value can never be NULL).
It’s easy to script this as a SQL Server Agent Job if you need it to run periodically.