문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top