How to import data with SSIS for sequential guids?
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 d开发者_如何学编程ata 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.
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
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.
精彩评论