我可以使用 DataTables 将数据从一个数据库导入到另一个数据库吗?

发布于 2024-08-15 08:07:41 字数 481 浏览 1 评论 0原文

我需要创建一个快速而肮脏的解决方案来将数据从数据库迁移到另一个数据库。这仅用于概念验证。从长远来看,我们将使用.NET 的同步框架。

数据库是相同的。该解决方案将用作 OCA(偶尔连接的应用程序)。

  • 我读到他们想要从某些 XML 迁移到哪些表。
  • 禁用每个表的目标上的所有约束。
  • 对于他们想要从中迁移数据的每个表,我从源创建一个数据表。
  • 创建一个指向目标的 DataTable。
  • 将所有行从源导入到目标并插入它们
  • 再次启用目标表上的所有约束。

我不确定以上是否可行。我已经完成了大部分工作,并且正在克隆源数据表。然后我遇到了克隆数据表没有指向任何地方的问题。

  • 我可以将其指向目标然后插入吗?
  • 有更好的方法吗?
  • 另一种方法是创建 INSERT INTO 语句,使用元数据来标识标识列,而不将它们包含在列名称中。

I need to create a quick and dirty solution to migrate data from database into another. This is only being used a proof of concept. Long term we will use .NET's Sync Framework.

The databases are identical. The solution is going to be used as an OCA (occasionally connected application).

  • I read in which tables they want to migrate from some XML.
  • Disable all constraints on the target for each table.
  • For each table they want to migrate data from I create a DataTable from the source.
  • Create a DataTable pointing to the target.
  • Import all the rows from the source into the target and insert them
  • Enable all constraints on the target tables again.

I am not sure if the above is possible. I had most of it working and I was cloning the source DataTable. I then had the problem where the cloned DataTable wasn't pointing anywhere.

  • Can I point it to the target and then insert?
  • Is there a better way to do this?
  • The alternative is to create INSERT INTO statements, using metadata to identify identity columns and not include them in the column names.

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

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

发布评论

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

评论(3

顾北清歌寒 2024-08-22 08:07:41

你提出的建议应该有效。但您可能会发现使用 SqlBulkCopy 类。

(这是一个以代码为中心的解决方案)

What you're proposing should work. But you might find it easier (and you'll definitely see better performance) with the SqlBulkCopy class.

(This is a code-focused solution)

迷爱 2024-08-22 08:07:41

简短回答:您可以加载 DataTable 并使用不同的 DataAdapter 将其保存到另一个数据库中。

但是,对于少代码的方法,您可以使用 SQL Server 数据库发布工具包此处说明

Short answer: You can load your DataTable and save it into another database by using a different DataAdapter.

But, for a code less approach, you can to use SQL Server Database Publishing Toolkit as stated here.

淑女气质 2024-08-22 08:07:41

您可以使用Sql Server 导入和导出向导 (dtswizard.exe )。
它创建一个 Integration Services 包,然后您可以随时保存并执行该包。

You can use the Sql Server Import and Export Wizard (dtswizard.exe).
It creates an Integration Services package that you can then save and execute whenever you want.

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