使用SSIS迁移和规范化数据库

发布于 2024-07-14 22:37:53 字数 872 浏览 5 评论 0原文

我们有一个 MS Access 数据库,希望将其迁移到具有新数据库设计的 SQL Server 数据库。 使用 SQL Server DB 的应用程序的一部分已经编写完成。

我四处寻找如何最轻松地完成迁移步骤,并从 Microsoft 的 SQL Server Integration Services (SSIS) 开始。 现在,出于标准化原因,我想垂直拆分表格。

一个虚构的示例如下所示

MS Access 表 person

ID
Name
Street

SQL Server 表 person

id
name

SQL Server 表 address

id
person_id
street

如何使用 SSIS 最好地完成此任务? id 列是标识(自动增量)列,因此我无法插入旧 ID。 如何将正确的 person_id 外键放入地址表中?

甚至可能有一个表必须分成三个表,其中 table2 中的一行属于 table1,table3 中的一行属于 table2 的行。

SSIS 是实现此目的的适当方法吗?

编辑 虽然这是一次性迁移,但我们需要一个自动化且可重复的过程,因为生产数据库使用率很高,并且我们正在开发环境中使用最近但不是最新的数据进行迁移。 我们计划进行一次迁移测试,并让客户审查该行为。 如果一切顺利,我们将进行真正的迁移。

大多数给定的解决方案都包含大量手动步骤,因此并不合适。

We have an MS Access database that we want to migrate to a SQL Server Database with a new DB design. A part of the application that uses the SQL Server DB is already written.

I looked around to find out how to do the migration step most easily and started with Microsofts SQL Server Integration Services (SSIS). Now I have gotten to the point that I want to split a table vertically for normalization reasons.

A made up example looks like this

MS Access table person

ID
Name
Street

SQL Server table person

id
name

SQL Server table address

id
person_id
street

How can I complete this task best with SSIS? The id columns are identity (autoincrement) columns, so I cannot insert the old ID. How can I put the correct person_id foreign key in the address table?

There might even be a table which has to be broken up into three tables, where a row in table2 belongs to table1 and a row in table3 belongs to a row table2.

Is SSIS the appropriate means for this?

EDIT
Although this is a one-time migration, we need to have an automated and repeatable process, because the production database is under heavy usage and we are working on the migration in our development environment with recent, but not up-to-date data. We plan for one test run of the migration and have the customer review the behaviour. If everything is fine, we will go for the real migration.

Most of the given solutions include lots of manual steps and are thus not appropriate.

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

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

发布评论

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

评论(5

迟到的我 2024-07-21 22:37:53

使用执行 SQL 任务并自己编写语句。

对于父表,请执行Select into table from table...,然后在进行过程中对其余表执行相同的操作。 确保将父表的标识插入设置为 ON 并重复使用旧的 ID。 这将帮助您保持数据完整性。

Use the execute SQL Task and write the statement yourself.

For the parent table do Select into table from table... then do the same for the rest as you progress. Make sure you set identity insert to ON for the parent table and reuse your old ID's. That will help you keep your data integrity.

甜柠檬 2024-07-21 22:37:53

要将 Access 表迁移到 SQL Server,请使用 SSMA,不是 Access 的升迁向导
您将获得更多可用的工具。

然后,您可以在 SQL Server 中一张一张地分解表。
我不确定是否有任何工具可以帮助您自动拆分表格,至少我找不到任何工具,但是手动完成并不太困难,尽管需要多少工作取决于您如何使用原始表格首先在您的 VBA 代码和表单中。

附注

关于标准化,不要太过分:我知道您的示例就是这样,但并不总是(很少?)需要标准化客户地址。

一个人可以有多少个地址?
如果您算上家庭地址、营业地址、送货地址、帐单地址,这可能是您需要的最多的地址。
在这种情况下,最好将它们放在同一个表中。 标准化数据只会需要更多的工作来重新组合,并且没有任何好处。
当然,在某些情况下,标准化是有意义的,但我看到人们过度接受这个概念(我也对此感到内疚),然后发现自己正在努力构建更复杂的查询来加入所有这些分裂数据,使开发和维护变得更加困难,并且经常在此过程中遭受性能损失。

For migrating your Access tables into SQL Server, use SSMA, not the Upsizing Wizard from Access.
You'll get a lot more tools at your disposal.

You can then break up your tables one by one from within SQL Server.
I'm not sure if there are any tools that can help you split your tables automatically, at least I couldn't find any, but it's not too difficult to do manually although how much work is required depends on how you used the original tables in your VBA code and forms in the first place.

A side note

Regarding normalization, don't go overboard with it: I know your example was just that but normalizing customer addresses is not always (rarely?) needed.

How many addresses can a person have?
If you count a home address, business address, delivery address, billing address, that's probably the most you'll ever need.
In that case, it's better to just keep them in the same table. Normalizing that data will just require more work to recombine and offers no benefit.
Of course, there are cases where it would make sense to normalise but I've seen people going overboard with the notion (I've been guilty of it as well) and then find themselves struggling to build more complex queries to join all that split data, making development and maintenance harder and often suffering a performance penalty in the process.

最后的乘客 2024-07-21 22:37:53

Access 是如此用户友好,为什么不在 Access 中标准化您的表,然后从那里扩大最终的结构呢?

Access is so user-friendly, why not normalize your tables in Access, and then upsize the finished structure from there?

悲念泪 2024-07-21 22:37:53

我找到了一个尚未提及的不同解决方案,它允许我们使用数据流任务的所有便利性和选项:

如果目标数据库位于本地 SQL Server 上,则可以使用数据流任务SQL Server 目标而不是 OLE DB 目标。
对于 SQL Server 目标,您可以标记“保留身份”选项。 (我不知道英文名称是否正确,因为我们有德语版本。)有了这个,你可以写入标识列

我们发现我们不能在任何地方使用旧的主键,因为我们有一些表采用并集来自多个表的记录。

我们通过构建一个包含列的临时映射表来开始该过程

new_id (identity)
old_id (int)
old_tablename (string)

。我们首先为新模式中的外键引用的每个表填充所有 old_id 。 new_id 值由 SQL Server 自动生成。

因此,我们可以在需要时使用连接将 old_id 转换为 new_id。 我们使用 new_id 值通过“保留身份”选项填充新表中的身份(主键)列,并且可以通过联接在映射表中简单地查找它们的外键。

I found a different solution which was not mentioned yet and allows us to use all the comfort and options of the dataflow task:

If the destination database is on a local SQL Server, you can use a dataflow task with SQL Server destination instead of an OLE DB destination.
For a SQL Server destination you can mark the "keep identities" option. (I do not know if the english names are correct, because we have a german version.) With this you can write into identity columns

We found that we cannot use the old primary keys everywhere, because we have some tables that take a union of records from multiple tables.

We start the process by building a temporary mapping table with columns

new_id (identity)
old_id (int)
old_tablename (string)

We first fill in all the old_id s for every table that is referenced by a foreign key in the new schema. The new_id values are generated automatically by SQL Server.

So we can use a join to translate from old_id to new_id where needed. We use the new_id values to fill the identity (primary key) columns in the new tables with the "keep identities" option and can simply look them up in our mapping table for the foreign keys by a join.

第七度阳光i 2024-07-21 22:37:53

您还可以查看 Jamie ThomsonSSIS 标准化器 组件。 我今天才发现(还没有实际尝试过)。 他发布的示例看起来很像您问题中的示例。

You might also look at Jamie Thomson's SSIS Normalizer component. I just found out about it today (haven't actually tried it yet). The example he posts looks a lot like the one in your question.

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