Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top