Example - Creating a Data Model

This section will show you how to set up a simple database "from scratch", just to get you started using the tools, without modifying any live data. If you follow the example literally, you will create a trivial "customer and orders database".

Important: You must create the target database needed in this example. You can use standard vendor-specific database tools to create the database.

Setting Up Databases

  1. Setup Driver. Select File->User Preferences if you are using Windows and Architect->Preferences if you are using Macintosh. Then select the JDBC Drivers tab. Select the database connection type you wish to use from the list on the left. If there is already a driver for the connection type you wish to use, click OK and go on to the next step. Otherwise, click the Add JAR button, navigate to where you have the driver Jar file installed, and click OK.

  2. Create a Connection. In the Database Tree section of the main window, right click and choose Add Source Connection->New Connection. For this example you can use a name like SampleDB for the Connection Name. Then select a data type you wish to use, which should be the driver you set before. Then fill the hostname, port, database, file if asked. The JDBC URL will automatically generate when you fill those blanks, so you don't have to type it an extra time. Fill in the Username and password (which is set on the server machine).

Designing a Database

You are now ready to design some tables. For this example, we will create the Customer and Orders table shown here.

  1. Click the New Table icon at the right side. The cursor will change to a crosshair. Move the cursor near the left of the Playpen area, and click. A "New Table" will appear.

  2. Also, the Table Properties Dialog will appear. Rename this table to Customers.

  3. Click the Insert Column icon, and a column property window will appear for the new column. Rename the column to customer_id and make it part of the primary key.

  4. Insert additional columns for Firstname, Lastname, Address, City, Province, Country Code [1] and Postal Code. The table should look something like the following:

  5. Create a second table, and name it Orders.

  6. Create columns named order_id (in the primary key), Quantity, Total Amount, and customer_id. Your project should now look something like the following:

  7. We need a relationship between these tables. An order should have a foreign key that refers to the customer. Click the "New Non-Identifying Relationship" icon. Select the Customers table, then the Orders table, and a link will be drawn as shown. Click this link and the keys that take part in the relationship will be highlighted in red.

Forward Engineer

  1. If you're happy with the database layout (you can always change it later), it's time to create the database. Click on the Forward Engineer button. You should see a window similar to the following:

  2. Set the "Create in" database to be the source connection we defined earlier. Set the database type to be the type that was set in the user preferences. Fill in the remaining fields based on the database type that was selected and press ok. You should see a window similar to:

  3. If this looks plausible, click Execute, and the tables and their relationship will be created. Congratulations! You have now created a simple database using the visual tools in Power*Architect.

Comparing Data Models

Suppose that after using this database, you realize that there should be a "shipping amount" field in the Order table (we never promised this would be completely realistic example).

  1. Select the Order table by clicking on its title.

  2. Click the Insert Column field and, as before, rename the New Column, this time to Shipping_Amount. Change its type to Decimal with precision 10 and scale 2.

  3. Now we need to compare two different Data Models, the original database and the current project. Click the Compare DM icon. Set the "Older" to Physical Database SampleDB (you may need to change the Schema to Public). Set the "Newer" to "Current Project" (since it is now newer than the database you created in Step 6). Set the output format to SQL.

    PS: swap button can help you easily swap the newer the the older.

  4. Click Start. You should see the SQL Preview window again, but this time with just an ADD for the column you just added:

  5. Click Execute, and the new column will be added to your database table.

When you exit the program, it will ask to save your project. Since you might want to alter this in future, to experiment with some of the other tools without damaging any live data, you may wish to save the Project file.

The remainder of this document provides a more comprehensive explanation of the various functions that Power*Architect offers.



[1] There is an ISO standard, ISO-3166, which specifies a two-letter code (and a rarely-used three letter code) for every country of the world: us for the United States, ca for Canada, and so on. Some developers like to use these in the Country field of a database, as we are doing here.