Giving a MYSQL Database a "version"
An alternative would be checking for each of the changes you want to make &mdash; does table foo exist, does column bar exist in table baz, and so on. Which sounds cleaner, perhaps, but means a lot more i/o.

So the best way would be something like 


int databaseVersion = getDatabaseVersion(); // because of course it's a function

try {
   if (databaseVersion &lt; 2) {
      // Update database schema to version 2
      databaseVersion = 2;
   }

   if (databaseVersion &lt; 3) {
      // Update database schema to version 3
      databaseVersion = 3;
   }

   // and so on...
}
finally {
   setDatabaseVersion(databaseVersion);
}


Don't forget to write the version to the database.

If you do not tie the database version number to your program version number (so databaseVersion &lt;> programVersion, but of course a specific version of your program has a specific version of the database), but instead increment the version number after each DDL statement you execute, this, coupled with the version being written in the finally, ensures that if for whatever reason the update crashes halfway through, the next time you can continue from that point on.