自动填充数据新增测试数据_用测试数据填充员工数据库

自动填充数据新增测试数据

In this article, we will examine the process of populating the employee database with dummy data, whose schema we designed in the previous article. Filling a SQL database with dummy data can be very useful when we want to run some tests. The most convenient way is the population of SQL tables with random data with the help of visual data generation tools.

在本文中,我们将研究用虚假数据填充员工数据库的过程,虚假数据是我们在上一篇文章中设计的。 当我们要运行一些测试时,用伪数据填充SQL数据库可能非常有用。 最方便的方法是借助可视数据生成工具来填充具有随机数据SQL表。

借助Data Generator for SQL Server生成数据 (Generating data with the help of Data Generator for SQL Server)

For this purposes we’ll use Data Generator for SQL Server tool which is integrated into SSMS and is also included in dbForge Studio. It should be noted that realistic test data is generated based on column names, dimensions, and data types. Apart from this, the relationships between tables are also taken into account, as the process of data generation depends on them.

为此,我们将使用SQL Server的数据生成器工具,该工具已集成到SSMS中,并且也包含在dbForge Studio中 。 应该注意的是,真实的测试数据是根据列名,维度和数据类型生成的。 除此之外,表之间的关系也要考虑在内,因为数据生成的过程取决于它们。

To open this component, right-click “New Data Generation…” on the necessary database in SSMS:

要打开此组件,请在SSMS的必要数据库上右键单击“ New Data Generation…”:

Image for post
Img. 1. Running the Data Generator for SQL Server tool in SSMS
图 1.在SSMS中运行SQL Server的数据生成器工具

If you are using dbForge Studio, in the main menu, choose Tools\New Data Generation…:

如果使用的是dbForge Studio,请在主菜单中选择“工具\新数据生成...”:

Image for post
Img.2. Running the Data Generator for SQL Server tool in dbForge Studio
图2。 在dbForge Studio中运行SQL Server的数据生成器工具

In the resulting window, on the “Connection” tab, you can see the current MS SQL Server instance and the database selected for data generation, which can be edited (if necessary). Then click the “Next” button:

在出现的窗口中,在“连接”选项卡上,您可以看到当前的MS SQL Server实例以及为生成数据而选择的数据库,可以对其进行编辑(如有必要)。 然后点击“下一步”按钮:

Image for post
Img.3. Setting the “Connection” tab
图3。 设置“连接”标签

Next, on the “Options” tab, let’s set the options of data generation for the database:

接下来,在“选项”选项卡上,让我们设置数据库的数据生成选项:

Image for post
Img.4. Setting data generation options
图4。 设置数据生成选项

Note that you can generate SQL test data in different modes:

请注意,您可以采用不同的方式生成SQL测试数据:

  1. By specified number of rows (1000 rows by default)

    按指定的行数(默认为1000行)
  2. By proportion of existing data in the volume of percent (10 % by default)

    按现有数据占百分比的比例(默认为10%)
  3. By generation of data by time (10 seconds by default)

    按时间生成数据(默认为10秒)

You can also clear data before generation by setting the “Truncate data from table before generation” parameter.

您还可以通过设置“在生成之前从表中截断数据”参数来生成之前清除数据。

You can set the value distribution mode in one of the following ways:

您可以通过以下方式之一设置值分配模式:

  1. Random by timestamp

    按时间戳随机
  2. Random by seed (1 by default)

    按种子随机(默认为1)
  3. Sequential

    顺序的

Also, you can set column properties:

另外,您可以设置列属性:

  1. Set values to be unique

    将值设置为唯一
  2. Include NULL values (10% of rows by default)

    包含NULL值(默认为行的10%)
  3. Include empty values (10% of rows by default)

    包含空值(默认情况下为行的10%)

You can save the settings to a .bat file by pressing the “Save Command Line…” button located on the lower left of the data generation settings window.

您可以通过按数据生成设置窗口左下角的“保存命令行...”按钮将设置保存到.bat文件。

After you are finished with the settings, on the lower right of the data generation settings window, press the “Open” button.

设置完成后,在数据生成设置窗口的右下角,按“打开”按钮。

You will then see a progress bar showing the table metadata loading. After that, the window with detailed data generation settings for each selected table appears:

然后,您将看到显示表元数据加载的进度条。 之后,将出现一个窗口,其中包含每个选定表的详细数据生成设置:

Image for post
Img.5. Detailed data generation settings for each selected table
图5。 每个选定表的详细数据生成设置

On the left, you should select the tables and columns you want to populate, and on the right, you should set the table generation mode for the selected table.

在左侧,应选择要填充的表和列,在右侧,应为所选表设置表生成模式。

At the same time, below are the instances of generated data (note that they represent real names).

同时,下面是生成的数据的实例(请注意,它们代表真实姓名)。

In the top right corner, there is a button of data generation settings that were described above.

在右上角,有一个上述数据生成设置的按钮。

To start the data generation process, click on the green arrow at the top center of the window. Then, you will see the window for selecting additional settings. Here, on the Output tab, you need to select exactly where to generate the data, in the form of a script, save it to a file or to a database. Let us select the last option and press Next:

要开始数据生成过程,请单击窗口顶部中心的绿色箭头。 然后,您将看到用于选择其他设置的窗口。 在这里,您需要在“输出”选项卡上以脚本的形式精确选择生成数据的位置,然后将其保存到文件或数据库中。 让我们选择最后一个选项,然后按Next:

Image for post
Img. 6. Setting the “Output” tab
图 6.设置“输出”选项卡

Then, you can set additional parameters on the Options tab. In this case, you need to uncheck database backup options and press “Next”:

然后,您可以在“选项”选项卡上设置其他参数。 在这种情况下,您需要取消选中数据库备份选项,然后按“下一步”:

Image for post
Img.7. Setting the “Options” tab
图7。 设置“选项”标签

On the “Additional Scripts” tab, you can set additional scripts. In our case, we just press “Next”:

在“其他脚本”选项卡上,可以设置其他脚本。 在我们的情况下,我们只需按“下一步”:

Image for post
Img.8. Setting the “Additional Scripts” tab
图8。 设置“其他脚本”选项卡

On the “Summary” tab, we can see the information about settings and also warnings. Here, you can also save all settings as a .bat file, by pressing the bottom left “Save Command Line…” button. To run the data generation process, you need to press the “Generate” button:

在“摘要”选项卡上,我们可以看到有关设置和警告的信息。 在这里,您还可以通过按左下角的“保存命令行...”按钮将所有设置另存为.bat文件。 要运行数据生成过程,您需要按“ Generate”按钮:

Image for post
Img.9. The general information and warnings on the Summary tab
图9。 摘要选项卡上的常规信息和警告

The window of data generation process appears:

出现数据生成过程窗口:

Image for post
Img.10. Data generation process
图10。 数据生成过程

Then, the tables will be populated with data. For instance, the Employee table has the following generated data:

然后,将在表中填充数据。 例如,Employee表具有以下生成的数据:

Image for post
Img.11. The examples of generated data in the Employee table
图11。 Employee表中生成的数据的示例

结论 (Conclusions)

To sum up, we populated the database with realistic data for testing both functionality and load. It is possible to generate much more random data for load tests. In addition to that, the very process of testing can be accelerated by means of the dbForge Unit Test tool.

综上所述,我们在数据库中填充了用于测试功能和负载的实际数据。 可以为负载测试生成更多随机数据。 除此之外,还可以通过dbForge单元测试工具来加速整个测试过程。

What is more, through the use of SQL data generation, you can calculate not only a database growth rate but also a query performance difference that results from the data volume increase.

而且,通过使用SQL数据生成,您不仅可以计算数据库增长率,还可以计算由于数据量增加而导致的查询性能差异。

Originally published at https://blog.devart.com on July 22, 2020.

最初于 2020年7月22日 发布在 https://blog.devart.com 上。

翻译自: https://towardsdatascience.com/populating-the-employee-database-with-test-data-aa76419eebb6

自动填充数据新增测试数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值