During import DynamicForm_AnswersSet_AnswersSetMetadata is duplicated
DELETE FROM DynamicForm_AnswersSet_AnswersSetMetadata WHERE AnswersSetMetadataID IN
(
SELECT AnswersSetMetadataID FROM
(
SELECT *, ROW_NUMBER() OVER (PARTITION BY md.ParentSetID, md.[Key] ORDER BY ParentSetID) AS CopyNumber
FROM DynamicForm_AnswersSet_AnswersSetMetadata AS md
) AS sub
WHERE sub.CopyNumber > 1
);
DELETE DynamicForm_AnswersSet_AnswersSetMetadata
FROM
DynamicForm_AnswersSet_AnswersSetMetadata d INNER JOIN (
SELECT AnswersSetMetadataID FROM (
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY md.ParentSetID, md.[Key] ORDER BY ParentSetID) AS CopyNumber
FROM
DynamicForm_AnswersSet_AnswersSetMetadata AS md
) AS sub
WHERE
sub.CopyNumber > 1
) m ON d.AnswersSetMetadataID = d.AnswersSetMetadataID