Generate 10 Customers with 5 Orders, each with 3 Order Lines
This example will show you how to create 10 Customers, each with 5 Orders, each with 3 Order Lines on the database. Each Order Line will also be associated to a Product.
In summary, this example will create:
- 10 Customers (numbered 101 to 110)
- 3 Products (numbered 1001 to 1003)
- 50 Orders (5 for each Customer, numbered 1 to 5)
- 150 Order Lines (3 for each Order, numbered 1 to 3)
To create the data execute the following Steps
- Close all dialogs to return to the TurboData primary window.
- Press the Insert Data tab.
- From the Scenario menu, select the New Scenario option.
- Enter the Name 'Customers with Orders', and press OK.
- The Edit Insert Scenario dialog will be opened automatically. Click on the 'Order Line' table, keep the mouse button down, and drag the arrow icon over to the right hand tree. Release the mouse button.

- Click on the Order Line table that you now see in the right tree to give it focus.
- Enter '1' in the Start Range, and '3' in the End Range
- Press the Set Foreign Keys push button. This will open the Set Foreign Keys dialog.

- On the diagram click on the Product box to select it.
- Set the Parent Table Start Range to '1001' and the Parent Table End Range to '1003'
- Select the option Yes - Parent data will be generated in this scenario.
- On the diagram select the Order box.
- Set the Parent Table Start Range to '1' and the Parent Table End Range to '5'
- Select the option Yes - Parent data will be generated in this scenario.
- Enter the data to Generate '3' Order Lines for each Order
- On the diagram select the Customer box.
- Set the Parent Table Start Range to '101' and the Parent Table End Range to '110'
- Select the option Yes - Parent data will be generated in this scenario.
- Enter the data to Generate '15' Order Lines for each Customer (3 for each of the 5 Orders)
- Press the Apply push button
- In the Child Table drop down list, select 'Order (1-5)'

- On the diagram select the Customer box.
- Press the Browse (…) push button to select the Customer Parent Table with the Start Range '101' and the End Range to '110'. This is the table that we are already using as a parent for Order Line.
- Enter the data to Generate '5' Orders for each Customer
- Press the Close push button. The foreign keys are now set up correctly.
- On returning to the Edit Insert Data dialog you will see that the Order, Product and Customer tables have been added to the list of tables for the creation of test data. You can move them to put the parents at the top, and children at the bottom to control the order in which the data is generated. To move a table, drag and drop it to a table that you want to position it above.

- Press the Generate push button to open the Generate SQL dialog

- Click on the Update Database option
- Press the Generate push button to Generate the data and automatically load it on to the target database.
- Press the View Data on Target DB push button to open the Edit Data dialog. If you examine the identifiers and the foreign keys you will see that 10 new Customers have been created with 5 Orders each, and 3 Order Lines for each of those Orders.

Figure 0.3 Each new Customer has 5 Orders

Figure 0.4 Each Order has 3 Order Lines