Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Schema Compare Tool for Oracle

0.00/5 (No votes)
20 Jul 2004 1  
This small VB.NET application allows you to compare Oracle database schemas against one another. This is very helpful when making sure your development instance is the same as your production instance; especially when implementing front-end changes.

Sample Image - OracleSchemaCompare.jpg

Introduction

This small VB.NET application allows you to compare Oracle database schemas against one another. This is very helpful when making sure your development instance is the same as your production instance; especially when implementing front-end changes.

Background

In rolling out a multi-tiered application, you may have to implement new or changed .NET assemblies, user-interfaces, and database changes in a synchronized fashion. You often need to make sure your production database has the same structure as the development or test instance before rolling out the .NET changes. How many times have you rolled out a .NET change and forgot that it required a database change like creating a view or modifying a stored procedure?

That's where this tool comes in handy.

Using the Tool

This VB.NET application comes ready to run. All you need is the .NET Framework 1.1 installed and the appropriate Oracle SQL*Net drivers because the application uses the System.Data.OracleClient for database access.

The first step is to create a "baseline" structure in XML. This is typically generated from the most up-to-date database and is used to compare other databases. You can use this single baseline to compare several other instances. This is helpful when you have to rollout changes to multiple install sites that all need to have the same database structure.

In the "Create Baseline" area, enter the database connection info and click "Build". This will query the Oracle data dictionary tables and build an XML file named "Baseline.xml" in your working directory. If you have already built a baseline, the application will read the XML file on startup and display the overview information as shown above.

Once the baseline has been generated, the "Compare Against Baseline" area becomes enabled allowing you to enter database log on criteria and click "Compare". The application will query the same data dictionary tables for the "Compare" schema and compare the results against the baseline. During the comparison, a log file is created named "ReconcileLog.txt" in your working directory.

After the compare is complete, the reconcile log is displayed in Notepad for your review. An example is given below:

In this example, we can see that the compared schema is missing a table named "NEWFUNCTB". We also see that the compared schema has an extra view that is not in the baseline named "PM_TRENDS_V", and that a column on the "WORKFLOWSTEP" table needs to be added. Although the actual code inside of stored procedures is not examined, we can see that the number of lines is different in the "BE_ACCESSGROUP" package, and can assume that the package probably contains changes.

The application compares the following database structure elements:

  • TABLES: Name, Columns, Column Data Types, Column Lengths, Column Nullable
  • VIEWS: Name, SQL Length
  • SEQUENCES: Name, Min Value, Max Value, Increment By, Cycle Flag
  • TRIGGERS: Name, Type, Triggering Event, Table Name
  • CONSTRAINTS: Name, Table Name, Type, Delete Rule
  • INDEXES: Name, Table Name, Uniqueness
  • DBMS_JOBS: What, Interval
  • PROCEDURES: Name
  • PACKAGES: Name, Line Count

Once the application has been run, these files will exist in the working directory:

  • Baseline.xml: Represents baseline schema. It can be read by a DataSet using ReadXml("Baseline.xml") if you want to use the data in your own application.
  • Config.xml: Contains the last usernames, passwords (encrypted), and databases. This is read on startup to populate the form fields.
  • ReconcileLog.txt: The last compare's results.

Points of Interest

It should be noted that this application compares database structure, not data. So if you need to add records to a table, for example, this application won't pick that change up.

I've tested this application on Oracle8i and Oracle9i. Earlier versions may or may not work.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here