Skip to main content
Forward Engineering

How to use forward engineering to generate SQL

SqlDBM Support avatar
Written by SqlDBM Support
Updated over a year ago

The Forward Engineering function in SqlDBM allows for the export of the database objects created in the SqlDBM project by generating SQL scripts. The Forward Engineering options allow you to specify which objects you want to export and whether they should be created as new objects or altered from a previous version.

SqlDBM can also forward engineer dbt source and model YAML. For more information, see the related article at the end of this page.

Note, SqlDBM will not make any changes directly to your database. The generated script should be run manually once it has been reviewed.

To get started, click on the Forward Engineer button from the left pane.

Generation Options

Generation options (on the right panel) apply at the project level. Familiarize yourself and set them accordingly before generating the SQL script.

Main

  • Safe Scripts - The script checks if an object exists before deleting or creating it, so there is no error when executing the script. It applies to CREATE and DROP statements (described below).

Database

  • Create schema - use only when creating the schema for the first time. The CREATE will fail if the schema already exists.

  • Drop schema - used to delete an existing schema. Be careful if objects already exist in the schema. Depending on your database parameters, this will either delete all objects in the schema or fail with a warning.

Table

  • Create - select to generate the CREATE table SQL for corresponding tables.

  • Drop - select to generate the DROP table SQL for corresponding tables.

Quote Options

  • Double Quotes - select to enable double quotes when generating object names (e.g., "My_Schema"."My_Table")

  • Empty - select to generate object names without quotes (e.g., My_Schema.My_Table)

File Format

  • Create - select to generate the CREATE file format SQL for corresponding formats.

  • Drop - select to generate the DROP file format SQL for corresponding formats.

Views

  • Create - select to generate the CREATE view SQL for corresponding views.

  • Drop - select to generate the DROP view SQL for corresponding views.

Generate SQL Script

To generate the DDL for the database objects created in your project, follow these three steps.

  1. Set the options (as described above)

  2. Select all or some of the objects you wish to generate

  3. Press the "Generate SQL" icon or button as indicated

Review the generated script on the next screen and run it in your database environment.

Use the broom icon to return to the "Forward Engineering" screen and start again.

Use the copy icon to copy the script to the clipboard for export.

Generate Alter Script

Use the Forward Engineering feature to generate an alter script with all the changes made between the current and any previous revisions.

Note that any unsaved changes will not be reflected until they are saved to a revision.

To generate the DDL for altered objects, follow these three steps.

  1. Set the options (as described above)

  2. Press the "Generate Alter SQL" icon or button as indicated (all modifications will be considered)

Select the "Generate Alter SQL" option.

Choose any previous revision to generate the later script.

Verify the script and proceed,

Use the broom icon to return to the "Forward Engineering" screen and start again.

Use the copy icon to copy the script to the clipboard for export.


See also:

Did this answer your question?