Set Foreign Keys

Figure 0.26 Set Foreign Keys

This is used to resolve the foreign keys for parent/child relationships to create meaningful test case scenarios.

A child table has foreign keys that point to a parent table. TurboData will generate default test data for the foreign key unless you set them to point to specific parent tables. Use a new parent table or select an existing parent that is already targetted by another foreign key by pressing the Browse (…) pushbutton. The system identifier can be used to determine which target parent has been selected if you have more than one in the list.

Select the child table with the foreign keys that you want to set. Enter the start and end range for the child table.

Select the child foreign key that needs setting differently to the default. Enter the start and end range of the parent for that foreign key.

If you also want to generate test data for the parent, select the option Yes Parent data will be generated in this scenario. This will add the parent table to the list of selected tables.

Enter the number of children you wish to generate for each parent.

The foreign key will now use the parents settings for the generation of data.

Helpful Hint: The target table's identifiers will default to it's start and end range numbers. To override the defaults, click on the checkbox to 'Select the target table for data generation'. Close this dialog, edit the Insert Data Scenario to override the key columns for the target table as desired. Come back to this dialog and uncheck the checkbox to 'Select the target table for data generation'. If you need to view or update your overrides, simply repeat this process.

The concept of this dialog is easiest to understand with examples:

Example 1.

In this example the child table is Order and the parent is Customer. The example will generate 10 Customers with 5 Orders each (numbered 1 to 5). This will give a total of 50 Orders. The data entered to accomplish this is as follows:

This results 50 Orders being generated ((1 to 5) * (1 to 10)).

The first set of Orders 1 to 5 are generated with the foreign key pointing to Customer 1, the second set of Orders 1 to 5 are generated with the foreign key pointing to Customer 2, and so on up to the tenth set of Orders 1 to 5 which are generated with the foreign key pointing to Customer 10. This is illustrated in the following table:

Order ID Foreign Key to Customer Id
1 1
2 1
3 1
4 1
5 1
1 2
2 2
3 2
4 2
5 2
1 10
2 10
3 10
4 10
5 10

Example 2.

In this example the child table is Order and the parent is Customer. The example will generate 10 Customers with 5 Orders each (numbered 1 to 50). This will also give a total of 50 Orders. The data entered to accomplish this is as follows:

This results 50 Orders being generated (1 to 50).

The first set of Orders 1 to 5 are generated with the foreign key pointing to Customer 1, the second set of Orders 6 to 10 are generated with the foreign key pointing to Customer 2, and so on up to the tenth set of Orders 46 to 50 which are generated with the foreign key pointing to Customer 10. This is illustrated in the following table:

Order ID Foreign Key to Customer Id
1 1
2 1
3 1
4 1
5 1
6 2
7 2
8 2
9 2
10 2
46 10
47 10
48 10
49 10
50 10

More:

Select an existing parent that is already targetted by another foreign key

Generate

Automatically Set Remaining FKs

Clear This FK

Clear FK Settings for ALL tables


Contents Previous Next