使用更新的父子键导入数据

发布于 2024-12-04 09:24:31 字数 290 浏览 3 评论 0原文

我有一个具有以下结构的表:

    [ID] [int] IDENTITY(1,1) NOT NULL,

    [ParentID] [int] FOREIGN KEY([ParentID]) REFERENCES [dbo].[tblTask] ([ID])

    [Name] [varchar](20)

该表已填充。

我需要从另一个类似的表导入数据,并且当然需要新的父子关系有效。是否有一些我可以使用的预先存在的功能或方法?

这是 MSSQL 2008

I have a table with this structure:

    [ID] [int] IDENTITY(1,1) NOT NULL,

    [ParentID] [int] FOREIGN KEY([ParentID]) REFERENCES [dbo].[tblTask] ([ID])

    [Name] [varchar](20)

This table is populated.

I need to import data from another similar table, and need the new parent-child relationships to be valid of course. Is there some pre-existing functionality or methodology that I can use?

This is MSSQL 2008

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

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

发布评论

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

评论(1

我很OK 2024-12-11 09:24:31

从评论来看,您似乎是在不必考虑其他并发插入的环境中进行此导入。

因此,在这种情况下,您只需 SET IDENTITY_INSERT ON 然后对源 id 应用偏移量,这样它们最终会比目标表中任何预先存在的 id 更大。

From the comments it seems you are doing this import in an environment where you don't have to consider other concurrent inserts.

So in this case you can just SET IDENTITY_INSERT ON then apply an offset to the source ids so they will end up larger than any pre-existing ids in the destination table.

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