db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Blair Zajac <bl...@orcaware.com>
Subject Re: Create table if not exists?
Date Sat, 21 Feb 2009 01:57:17 GMT
Chris wrote:
> MySQL has a really nice syntax for creating tables if they don't exist 
> already:
> 
> CREATE TABLE IF NOT EXISTS foo (...)
> 
> How can I get the same functionality in Derby? I haven't been able to 
> figure out the SQL command to check for the existence of a table.

You can use this (Scala code follows):

       val metadata = connection.getMetaData
       val rs = metadata.getTables(null,
                                   null,
                                   null,
                                   Array("TABLE"))

This should work for any database, but I know it works for Derby, PostgreSQL and 
Oracle.

Regards,
Blair


Mime
View raw message