SQL Data Generator 3

Worked example - setting up the data generator

This topic provides an overview of how you set up SQL Data Generator to generate data.

You are recommended to back up the database that you are going to populate before you generate the data; you can then adjust the settings and repeat the data generation if you are not happy with the results.

To generate data, first create a project by selecting the SQL Server and database you want to populate. The project also defines some options for the data generation, and you can specify any number of SQL scripts that you want SQL Data Generator to run automatically before or after generating the data.

When you have created a project, the schema of the database you selected is listed in a tree view in the Tables to populate pane.

You specify the tables that you want to populate by selecting the Populate check box. By default, these are all selected, but you can change this option for both new projects and new tables in your application options (accessed from the Tools menu).

To see the creation SQL script for a table, right-click the table or column name in the tree view and click Show Schema Creation Script.

When you have selected the Populate check box for a table, you can define how you want the data to be generated: click the table name in the Tables to populate pane, and specify the details in the Table generation settings pane.

You can choose to:

  • create data using generators
    SQL Data Generator automatically assigns a generator to each column based on its table name, column name, data type, and length. If the column has constraints, SQL Data Generator uses these to set the generator parameters for the column; if the constraints cannot be complied with in this way, the RegexpGenerator is assigned instead and an appropriate regular expression is set up. You can change the generator used by a particular column later if required. For detailed information, see Using generators.
  • import data
    You can import a table or view from an existing database, or an existing CSV file. SQL Data Generator maps the columns based on name and data type. If any columns cannot be mapped, SQL Data Generator assigns a generator. You can change the mappings later if required. For detailed information, see Mapping SQL tables or views and Mapping CSV files.
  • Foreign keys are automatically assigned the Foreign Key generator; this cannot be changed to a different generator, but you can customize its settings.
  • Columns for which data is auto-generated display Server Assigned in the Generator box; this cannot be changed.
    For example computed columns are server assigned (identity columns can be copied since version 3.1.4).

In the table generation settings, you can also specify the number of rows that you want to be generated, and whether you want existing data to be deleted prior to populating the table.

You can preview the data that will be generated for each table in the Preview pane.

You may see the following icons when the values for a column cannot be previewed prior to generation:

server-assigned column
foreign key column
computed column or a manual foreign key column

You may also see warnings or errors in the preview.

When you have set the table-level parameters, you can check the settings for each column in the table, and customize them if required. To select a column for customization, click the name of the column in the Tables to populate pane, or click the column in the Preview pane.

When you are happy with the settings for all the columns that you want to populate, click Generate Data. An action plan provides a summary of the data generation for you to review before you generate.

Scripts

You can run SQL scripts before or after the data generation. For example, you could use scripts to add custom data to the database. SQL Data Generator can run these scripts automatically.

You set up the scripts you want to run in the Project Configuration dialog box (click Edit Project and select the Scripts tab).

You can link to external script files, or you can embed scripts by typing in the Project Configuration dialog box, (or a combination of the two). Scripts are run in the order in which you list them in the project configuration.

If a script that is run before data generation fails, the generation process is stopped.

If a script that is run after data generation fails, the process continues with the next script.

You can use $Server$ and $Database$ variables in your scripts.

Use these variables if you want to use the database connection specified in the project or the command line.

Warnings and errors

When you are setting up the tables and columns that you want to populate, SQL Data Generator displays warning and error messages to inform you when there may be a problem with the data generation.

Errors prevent you from selecting  Generate Data. For example, an error is displayed if there are circular dependencies.
Warnings inform you when a problem may arise during data generation. The problem does not prevent you from generating data, but it may stop the data generation for a particular table. For example, a warning is displayed if you have chosen to delete rows in a table, but another table references it.
Information messages provide you with information about issues that you may want to rectify, but which will not prevent data generation. For example, you may see an information message if SQL Data Generator cannot create enough rows for the preview.

To see the details of an error or warning, hover your mouse pointer over the icon to display a tooltip, or click the column name to see the details in the Column generation settings pane.

Refreshing the schema

When you open a project, if the database schema has changed since you created the project, the schema that has changed is flagged with in the Tables to populate pane. For example, a changed column is indicated by and a changed primary key column is indicated by .

To clear the flags, click Refresh Schema.

You can also click Refresh Schema to see any changes that have been made to the schema since you opened it. Click Refresh Schema again to clear the flags.

Command line

When you have set up a SQL Data Generator project, you can use the command line to run the project. For more information, see: Using the command line.


Didn't find what you were looking for?