Thanks everybody for the help! Here is what I ended up with:
USE DiabloLootSystemClone
Go
DECLARE @counter int
SET @counter = 1
WHILE @counter <= 1000
BEGIN
INSERT ChestItems
SELECT c.ChestID
,i.ItemID
FROM Chests c
CROSS APPLY (SELECT TOP ((ABS(CHECKSUM(NEWID())) % (c.ChestTier * 2)) + 1)
Items.ItemID
FROM Items
WHERE Items.ItemTier = c.ChestTier) i
WHERE c.ChestID = @counter
SET @counter += 1
END
GO
I was having a problem setting the foreign keys on the Items and Chests tables and I'd appreciate some feedback on my implementation. I just ended up creating triggers to set them from the inserted table:
CREATE TRIGGER uAddItemsFK ON ChestItems
AFTER INSERT
AS
BEGIN
UPDATE Items
SET
Items.ChestItemsID = i.ChestItemsID
FROM
Items it
JOIN inserted i
ON it.ItemID = i.ItemID
END
GO
CREATE TRIGGER uAddChestsFK ON ChestItems
AFTER INSERT
AS
BEGIN
UPDATE Chests
SET
Chests.ChestItemsID = i.ChestItemsID
FROM
Chests c
JOIN inserted i
ON c.ChestID = i.ChestID
END
GO
Thanks Again, everybody!