0

I have created a SQL Server table with a column specified with a unique constraint. When doing frequent inserts into that table, how does this constraint get enforced; does SQL Server check the entire table? Does an attempt to insert a duplicate row mean it creates a deadlock, or does it only return an error message?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ezhumalai
  • 163
  • 1
  • 2
  • 10
  • 2
    Does this answer your question? [SQL SERVER: Unique Constraint Explanation](https://stackoverflow.com/questions/47072855/sql-server-unique-constraint-explanation) – Alejandro Mar 30 '21 at 14:49
  • Not exact, does unique constraints create deadlock issue? While insert duplicate row means. – Ezhumalai Mar 30 '21 at 14:59
  • 3
    A constraint does not "create deadlock issues". It is your code, your transaction boundaries, and the order of locks taken during the execution of your queries that can lead to deadlock. – SMor Mar 30 '21 at 15:07
  • 3
    Constraints always create errors when inserting invalid data (be either with unique indexes, foreing keys and checks). They don't produce by themselves deadlocks. – Alejandro Mar 30 '21 at 15:11

0 Answers0