• As twin.devil already pointed out, if you use MERGE instead of a simple UPDATE, it will automatically raise an error if you try to update the same record twice. Otherwise, you can use an IF statement to check for duplicates and run the update if there are no duplicates and raise an error if there are duplicates.

    DECLARE @SampleTable TABLE ( table_id INT, table_date DATE )

    INSERT @SampleTable( table_id )

    VALUES (1), (1)

    IF NOT EXISTS ( SELECT table_id FROM @SampleTable GROUP BY table_id HAVING COUNT(*) > 1)

    UPDATE @SampleTable

    SET table_date = SYSDATETIME()

    ELSE

    RAISERROR('Duplicate IDs found. Cannot update.', 16, 1)

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA