使用测试数据填充表,同时保持关系完整性

发布于 2024-10-08 20:12:15 字数 221 浏览 3 评论 0原文

我有一个带有 InnoDB 表的 MySQL 数据库,其中许多表都有外键。

我打算编写一个脚本来用测试数据(10-20k 行或更多)填充表,但我想我应该询问是否已经有一些东西可以根据字段类型生成测试数据,但确保关系完整性同时?

我已经在 generateddata.com 上看到并下载了该脚本,但据我所知,它很聪明,但它不会读取数据库中的表并根据它找到的内容生成数据 - 您必须手动完成这一切。

I have a MySQL database with InnoDB tables, many of which have foreign keys.

I was going to write a script to populate the tables with test data (10-20k rows or more) but I thought I ought to ask if there's something already out there that can generate test data based on the field types but ensure relational integrity at the same time?

I've seen and have downloaded the script at generatedata.com but as far as I can see it's clever but it won't read the tables within your db and generate data based on what it finds- you have to do it all manually.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌面超妹 2024-10-15 20:12:15

这很简单:

call procedurename('DATABASE','TABLE',1000,''); 

将填充 1000 个随机行并根据您的需要填充记录。

This one is as easy as:

call procedurename('DATABASE','TABLE',1000,''); 

will fill 1000 random rows and will populate records as per your needs.

在梵高的星空下 2024-10-15 20:12:15

编辑:正如 Mark Byers 所指出的,Red-Gate 工具仅适用于 SQL Server。

Red-Gate 有他们的 SQL 数据生成器 其特点是“外键支持跨多个表生成一致的数据”,但它并不便宜。

Datanamic 有一款名为 数据库数据生成器

我没有使用过这些产品,但我使用过两家公司的其他工具,发现它们非常好。

EDIT: As pointed out by Mark Byers the Red-Gate tool is SQL Server only.

Red-Gate have their SQL Data Generator which features "Foreign key support for generating consistent data across multiple tables" but it's not cheap.

There is a product from Datanamic called DB Data Generator.

I have not used either of these products but I have used other tools from both companies and found them to be very good.

临走之时 2024-10-15 20:12:15

我使用单独的连接脚本。这样,我可以创建一个测试数据库(真实数据库的副本)。我在那里添加我的测试数据。

然后,连接脚本中的一行用于选择测试数据库,当我准备好时,一行将更改回实时数据库。

它非常适合玩耍、设计、测试等。

这是一个示例:

文件名:includes/connection.php

<?php

    $DB_USER='username';          
    $DB_PASS='password';             
    $DB_HOST='localhost';                   
    $DB_NAME='dbname'; 

?>

要查看测试数据库,我将最后一行更改为:

 $DB_NAME='testdbname';

然后,我在每个 PHP 脚本中包含此连接文件。

希望这有帮助。

I use a seperate connection script. This way, I can create a test database (a duplicate of the real db). I add my test data there.

Then it's one line in the connection script to select the test db, and when I'm ready, one line to change back to the live db.

It's great for playing, designing, testing etc.

Here is an example:

filename: includes/connection.php

<?php

    $DB_USER='username';          
    $DB_PASS='password';             
    $DB_HOST='localhost';                   
    $DB_NAME='dbname'; 

?>

To look at the test db, I change the last line to:

 $DB_NAME='testdbname';

Then, I include this connection file in each PHP script.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文