Devart Blog

Generating Related Data Elements with dbForge Data Generator for SQL Server

Posted by on April 1st, 2016

Recently we got an interesting question from our user:

The docs don’t address directly, but how can we generate three related data elements, like date of birth, age, and date of death for instance, in one script efficiently as it generates test rows/records and then populate the fields in a test database table? If docs do address this, please point me to where, if you would… Thanks!

Another user has posted the similar question on the Devart support forum.

We added the new “Death Date” generator to help resolve the problem. Actually, it is the most “sad” generator in our list. Let’s have a look at how to use it.

Here is a demo table that contains the PersonAge, DateofBirth, and DateofDeath fields.

dod_table

 

Let’s start dbForge Data Generator for SQL Server and populate the table with test data.

dod_start_data_gen

 

We see a warning that states that the global name “DOB” is not defined. DOB is the column that contains dates of birth. It must be located in the same table.

Select the DateofDeath column to see the details. As you can see, the Death Date generator is automatically selected and mapped to the column.

The following step is to modify the python script. Find the bd = DOB string. It is required to replace the DOB palceholder with the actual column that contains dates of birth (DateofBirth in our case). Note, it is case sensitive. Thus, in this particular example, we need to write bd = DateofBirth

Click the screenshot to enlarge.

dod_default_python1

 

Once you have modified the python script with the correct column name, another warning appears in the DateofDeath column (String was not recognized as a valid DateTime).

dod_modified_python1

 

The reason is that we have the different column data format by default.

dod_default_date_format

 

So the last step is to replace “/” with the “.” Once it is done, the required data is generated.

dod_result

 

To generate the correct Person age date, that corresponds to DateofBirth and DateofDeath, select the PersonAge column and specify appropriate columns instead of placeholders. Also, keep in mind that the date format may require some modifications.

dod_actual_person_age

 

Here is the result:

DoD_result_page

This way you can generate related data elements. The python script is well commented and you can modify it to use for your own purposes.

Leave a Reply