Skip to content

Custom SQL Scripts

Custom SQL scripts let you add SQL that should run alongside generated DDL when DBModeler’s built-in model is not enough.

Use custom SQL scripts when you need logic such as:

  • helper objects created before tables
  • post-table adjustments or patch logic
  • hand-authored SQL that belongs to a specific version

Scripts are version-scoped, so they live with the checkpoint they belong to.

DBModeler uses two execution phases:

  • PRE_TABLES for SQL that should run before generated table DDL
  • POST_TABLES for SQL that should run after generated DDL

This keeps custom logic aligned with generated schema output.

From the scripts dialog you can:

  • create a script
  • name it
  • choose the phase
  • edit the SQL body
  • reorder scripts within the same phase

The editor helps with authoring, but SQL correctness is still your responsibility.

When you export migration SQL up to a given version, DBModeler can accumulate scripts from previous finalized versions.

This matters when a deployment needs the full chain of custom SQL, not just the newest script.

If a newer version needs to replace an earlier custom script, you can mark the new script as superseding the older one.

Use this when a previous script should no longer participate in the accumulated export path.

  • Keep scripts narrowly scoped to the version that introduced them.
  • Use PRE_TABLES only when ordering truly matters.
  • Re-run SQL preview after adding or reordering scripts.
  • Prefer clear script names that describe purpose, not just timing.

Next: Versions and Migrations and Export SQL