views:

108

answers:

3

Is there a dialect of XML for defining the tables, indexes and relations of a relational database, and a "compiler" or stylesheet to transform that definition into SQL CREATE statements (DDL)?

EG, something that might look like:

<Table Name="orders">
    <Column Name="order_id" Type="varchar" Size="20"/>
    ... etc ...
</Table>

I'd like to keep the configuration of a service and its dependencies all in one place, and XML is looking like the best choice because of its wide support and its ability to mix namespaces. With it, I could write an installation program that can install this service and create the database, its tables, indexes, relations, etc. without being tied to a specific SQL implementation.

Edit: This has nothing to do with ORM.

A: 

Sounds like XML based migrations, never seen one though.

If you're into OR/M you could take a look at (N)Hibernate's hbm2ddl tool. It generates the appropriate create commands for the schema on various database dialects out of an XML definition.

Cristian Libardo
hbm2ddl looks like the right kind of thing. I'm not going to be using NHibernate, though: can the DDL creator be used independently?
C. Lawrence Wenham
+2  A: 

Something like xml2ddl?

sanxiyn
A: 

I've written my own a couple of times for different projects. If you're good at XSLT, knowledgeable about DDL, and have a good development environment, it's surprisingly easy (like, 2 or 3 hours work) to hack together a schema for representing metadata and a transform that produces your database-creation script.

This has all the usual advantages and disadvantages of doing it yourself: on the one hand, you control the feature set, but on the other hand, you're responsible for the feature set. In my projects, the feature set was small enough that it was easier to build it myself than it would have been to learn how to work with someone else's application framework.

Robert Rossney