On Microsoft SQL Server 2008, I have a table with Products:
Id | Name | DefaultImageId
And one with Images:
Id | ProductId |
Addressing @philreed's issue with the selected answer:
Is there a way to assign each row being updated with a different value randomly chosen from the source table?
UPDATE Products
SET DefaultImageId = t2.Id
FROM Products t1
CROSS APPLY (
SELECT TOP 1 Id
FROM Images
WHERE t1.Id = t1.Id
ORDER BY newid()
) t2