Model the database

From the database meta-schema file, you can graphically model a database by adding tables and constraints and generate a database creation script.

The database meta-schema file will contain the information about the tables, columns, and relations of the relational database that is needed by your app. By default, the database meta-schema file mydatabase.4dbx has been provided for you.

Tip: This procedure uses the provided default database. To rename the database file, see Rename the database in a BAM Mobile project.
  1. In the Project group, expand the Database node, and double-click on the 4dbx to open it. The Meta-Schema Manager is launched for viewing and modifying the schema.
    Note: The meta-schema diagram includes a seqreg table. For this quick start, you do not need to worry about this table. For more information about what this table does, see Managing SERIALs in a generated application
  2. Right-click and select Add Table. Set the table's name property to account. Right-click on the table to add the columns as shown.

    Figure: Create table


    Account table with id, firstname, lastname, company, and phone columns.
  3. Make the id column SERIAL and not null. Make the id column the primary key for the table. With the table selected, right-click to see the menu option for adding a constraint.

    Figure: Set primary key


    Screenshot of dialog to add a constraint or index.
  4. Save your file.
  5. Right-click on the 4dbx file in your project and select Generate Database Creation Script. Select the option to populate database with sample data and then Generate.

    Figure: Generate Database Creation Script


    Screenshot of Database Generation Script dialog.
  6. Save the file to the databaseMaintenance directory of your project ($ProjectDir) to overwrite the default file with your file.
    1. Uncheck the Insert the file in the project option as the file is already in the project; you are just saving the file to disk.

    Figure: Save to databaseMaintenance sub directory


    Screenshot of Save As dialog showing file save to databaseMaintenance directory.
  7. In the project, expand the DatabaseMaintenance group. Right-click on the CreateDatabase program and select Execute. This will compile and run your script, creating and populating the database.