A Brief Example

This section will show you how to set up [2] 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".

  1. Setup Driver. Select File->User Preferences and select the JDBC Drivers tab. If there is already an entry for the driver you wish to use,, click OK and go on to the next step. Otherwise, click the Add 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 both the Connection Name and the Database name (these names do not have to be the same, but we'll keep them the same for simplicity). If you select the JDBC Driver before you type the database name, then as you type the Database name, it will be added to the DB URL, so you don't have to type it an extra time. Fill in all the fields and click OK.

  3. Now right click on the Project in the Database tree, and select Set Target Database, then choose the Database connection you just created (e.g., SampleHSQLDB). Note that Add Source Connection makes a database available to copy tables from, whereas Set Target Database specifies where SQL commands will get executed to create the structure you are building in your project.

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

    1. Click on 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. Double click on the title, and the Table Properties Dialog will appear. Rename this table to Customer, and the Primary Key to Customer_PK.

    3. Click on the Insert Column icon, and a "New Column" will appear. Double-click on the column, or click on the Column Properties, and the Column Properties Dialog will appear. Rename the column to ID and make it part of the primary key.

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

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

    6. Create columns named Id (in the primary key), Quantity, and Total Amount. 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 Order table, then the Customer table, and a link will be drawn as shown. Click on this link and the keys that take part in the relationship will be highlighted in red.

  5. 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:

  6. 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. But let's not stop here. 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).

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

  8. Click the Insert Column field and, as before, rename the New Column, this time to Shipping_Amount. Change its type to Decimal(10,2).

  9. 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.

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

  11. 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.



[2] Assumes you have used some vendor-specific external tool to create a new database.

[3] 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.