如何使用 SSIS 导入数据以实现顺序指南?

发布于 2024-08-20 03:14:20 字数 177 浏览 7 评论 0原文

无论如何,是否可以将数据导入到 SSIS 中,而我希望 PK 是连续的 guid?

到目前为止,我能想到的唯一方法是创建一个临时表,其中的列默认为 newsequentialid() 加载其中的数据,然后将其复制到正确的表。这不是很优雅,而且需要在我的包中添加一堆额外的层来适应这一点,这有点耗时。

Is there anyway to import data into SSIS where I expect the PKs to be sequential guids?

The only method I've been able to come up with so far is to create a temporary table with the column defaulting to newsequentialid() loading the data in there then copying it to the correct table. This isn't very elegant and is somewhat time consuming of having to add a bunch of extra layers in my packages to accommodate this.

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

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

发布评论

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

评论(2

遥远的她 2024-08-27 03:14:20

您是否看过OUTPUT 子句

基本上,您输出插入到表变量或临时表中的任何内容(包括标识字段)。如果另一个表有外键关系,则不能直接将其插入到另一个表中。每当我使用它时,我都会使用临时表,然后从那里插入到子表中。

下面是它的使用示例:

DECLARE @roles TABLE (
    SecurityRoleId int
)

INSERT dbo.SecurityRole (
    SecurityRoleName,
    SecurityRoleDescription,
    LastUpdatedGuid
)
OUTPUT
    INSERTED.SecurityRoleId
INTO @roles
SELECT
    SecurityRoleName,
    SecurityRoleDescription,
    NEWID()
FROM @SecurityRole


INSERT INTO dbo.SecurityRoleDtl (
    SecurityRoleId,
    MemberSecurityRoleId
)
SELECT
    1,
    SecurityRoleId
FROM @roles

Have you looked at the OUTPUT clause?

Basically, you output anything that was inserted (including identity fields) into a table variable or a temp table. You can't insert it directly into another table if the other table has a foreign key relationship. Whenever I have used it, I used a temp table and then inserted from there into the child table.

Here is an example of its use:

DECLARE @roles TABLE (
    SecurityRoleId int
)

INSERT dbo.SecurityRole (
    SecurityRoleName,
    SecurityRoleDescription,
    LastUpdatedGuid
)
OUTPUT
    INSERTED.SecurityRoleId
INTO @roles
SELECT
    SecurityRoleName,
    SecurityRoleDescription,
    NEWID()
FROM @SecurityRole


INSERT INTO dbo.SecurityRoleDtl (
    SecurityRoleId,
    MemberSecurityRoleId
)
SELECT
    1,
    SecurityRoleId
FROM @roles
北笙凉宸 2024-08-27 03:14:20

我不使用 GUID 作为 PK,但您不能将 newsequentialid() 设置为默认值,然后对数据库的任何插入都将使用它。

I don;t use GUIDs as PKs but can't you set newsequentialid() as the default value, then any insert to your datbase will use that.

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