Is the following SQL atomic? is there any risk for two rows with the same id
?
INSERT INTO [dbo].[table] (id, whatever)
SELECT *
FROM (SELECT '00000000-0000-0000-0000-000000000001' as id,
'something' as whatever)
AS input
WHERE NOT EXISTS (SELECT 1
FROM [dbo].[table]
WHERE id = '00000000-0000-0000-0000-000000000001')
I'm using it in Azure Synapse, in which there is no primary key enforcement and MERGE
-UPDATE
is not allowed from whatever reason.