UNIQUE CONSTRAINT VIOLATION error occurs when the constraints defined on the table in the database is violated. This can happen when you define Primary constraint on a column and that’s violated by duplicate or not null values entered. So to avoid this error you have to be careful, which means you cannot insert the same key twice in other words you cannot have duplicate primary keys.
It can also come when Unique constraint is violated. Unique constraints are done on columns to avoid duplicate records in the table. The Unique Constraint is implemented on the important columns. This ensures that the records are never duplicated but it can be null values.