I could only think you need to add error handling in your code
Example: you can think of following code to handle the duplicate key issue
BEGIN TRY
CREATE UNIQUE CLUSTERED INDEX ix_tblname ON tblname (col1,col2)
END TRY
BEGIN CATCH
;WITH dupes AS
(SELECT * , ROW_NUMBER() OVER ( PARTITION BY col1,col2 ORDER BY col1, col2) AS Rownum FROM tblname )
DELETE FROM dupes
OUTPUT DELETED.* INTO #Log
WHERE Rownum > 1
CREATE UNIQUE CLUSTERED INDEX ix_tblname ON tblname (col1,col2)
END CATCH