I have a table with million of records.
I have this query:
INSERT INTO t1 (recordA, recordB, inserttime)
SELECT recordA, recordB, GETDATE()
FROM t1 as l1
WHERE
l1.id_comp = @id_comp
AND l1.id_sq NOT IN (SELECT l2.id_sqa
FROM leghe_formazioni as l2
WHERE l2.id_comp = @id_comp)
And sometimes duplicate records and sometimes not.
The duplicate record have the same insert time.