4.14. Schema Tool

Most users will only access the schema tool indirectly, through the interfaces provided by other tools. You may find, however, that the schema tool is a powerful utility in its own right. The schema tool has two functions:

  1. To reflect on the current database schema, optionally translating it to an XML representation for further manipulation.

  2. To take in an XML schema definition, calculate the differences between the XML and the existing database schema, and apply the necessary changes to make the database match the XML.

The XML format used by the schema tool abstracts away the differences between SQL dialects used by different database vendors. The tool also automatically adapts its SQL to meet foreign key dependencies. Thus the schema tool is useful as a general way to manipulate schemas.

You can invoke the schema tool through the schematool shell/bat script included in the Kodo distribution, or through its Java class, kodo.jdbc.schema.SchemaTool. In addition to the universal flags of the configuration framework, the schema tool accepts the following command line arguments:

The schema tool also accepts an -action or -a flag. The available actions are:


The schema tool manipulates tables, columns, indexes, constraints, and sequences. It cannot create or drop the database schema objects in which the tables reside, however. If your XML documents refer to named database schemas, those schemas must exist.

We present some examples of schema tool usage below.

Example 4.17. Schema Creation

Add the necessary schema components to the database to match the given XML document, but don't drop any data:

schematool targetSchema.xml

Example 4.18. SQL Scripting

Repeat the same action as the first example, but this time don't change the database. Instead, write any planned changes to a SQL script:

schematool -f script.sql targetSchema.xml

Write a SQL script that will re-create the current database:

schematool -a createDB -f script.sql

Example 4.19. Schema Drop

Drop the current database:

schematool -a dropDB

Example 4.20. Schema Reflection

Write an XML representation of the current schema to file schema.xml.

schematool -a reflect -f schema.xml


Skip navigation bar   Back to Top