It is possible to (pretty much) standard method to check not just whether a table named
mytable is available, but additionally be it schema is comparable to what it ought to be? I am experimentation with H2 database, and
CREATE TABLE IF NOT EXISTS mytable (....)
claims apparently only look for the table´s title. I'd be prepared to have an exception if there is a table using the given title, but different schema.
I'm not conscious of any database which has this feature natively.
Haven't tried on the extender (folded my very own code to get this done) but maybe Apache DdlUtils might help.
It's a tricky factor to complete, particularly if you would like it to use different database suppliers. Also, you will find most likely different opinions about how exactly similar the schema must be to be able to pass. Column names, column order, column types, primary key definition: certainly. But what about constraints, what they are called from the constraints, table space definitions, and so forth?
CREATE TABLE IF NOT EXISTS ... isn't a standard SQL code.
The one thing to complete is to see if the table has already been within the catalogue.
For example, in Java you might make a move like:
connection.getMetaData().getTables(connection.getCatalog(), null, null, null)
For more information see javadoc java.sql.Connection.
Twofold answer :
(a) The presence of a table is one thing that needs to be made certain through the installation process of a credit card applicatoin, not through the application itself at run-time.
(b) Should you think you've got a justification for deviating from (a), you could attempt and query the catalog, the industry database composed of tables whose structure is, pretty much, recommended through the INFORMATION_SCHEMA from the SQL standard. Which tables exist, which posts they've, which data types individuals posts are, which secrets are declared, etc. etc., it's all regulated inside.
In reaction to :
"Yes, I additionally believe that while a) might be the typical approach to take, it much like, say, "the presence of a C: drive is one thing that needs to be made certain through the installation process of a credit card applicatoin, not through the application itself at run-time.". But a significant application should make no presumptions concerning the atmosphere. Rather, it will check it. Conditions can alter - and eventually they'll.Inch
Should you deploy the application on any flavour of Unix/AIX OS, you'd experience serious problems in case your application attempted to say the presence of a C: drive at run-time.
That's PRECISELY exactly why programs should NOT verify install-time parameters/conditions at run-time.