add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE ResultTable ([primaryKey] UNIQUEIDENTIFIER,[foreignA] INT, [foreignB] INT)
CREATE TABLE foreignTableB(primaryKey INT);

INSERT INTO foreignTableB(primaryKey)
VALUES (1),(2),(3),(4),(5),(100),(1000);

DECLARE @foreignKeyA INT = 1;

INSERT ResultTable ([primaryKey],[foreignA], [foreignB])
SELECT
CAST(CAST(CHECKSUM(@foreignKeyA, fb.primaryKey) AS VARBINARY(4)) AS UNIQUEIDENTIFIER)
,@foreignKeyA
,fb.[primaryKey]
FROM foreignTableB as fb;
14 rows affected
SELECT *
FROM ResultTable;
primaryKey foreignA foreignB
11000000-0000-0000-0000-000000000000 1 1
12000000-0000-0000-0000-000000000000 1 2
13000000-0000-0000-0000-000000000000 1 3
14000000-0000-0000-0000-000000000000 1 4
15000000-0000-0000-0000-000000000000 1 5
74000000-0000-0000-0000-000000000000 1 100
f8030000-0000-0000-0000-000000000000 1 1000