"Key Violation" is a common error when inserting or updating data in a table in a (relational) database.

A Key Violation occurs when a table has a primary key defined on one or more of the fields, and you are trying to insert or update data so that there would be more than one row with the same key value(s).

Here is an example table. The field nickname is the primary key for the table.

+---------------------------------+
| nickname | firstname | lastname |
+---------------------------------+
| johnny   | John      | Doe      |
| root     | System    | Admin    |
| steve    | Steve     | Smith    |
+---------------------------------+

A Key Violation occurs if we try to:

  • Insert a row with the value 'johnny', 'root' or 'steve' in the nickname field
  • Update the nickname field of an existing row to the same value as another.

Note that it is perfectly OK to have two rows with the same value in the firstname or lastname fields, since those fields are not part of the primary key.

Log in or registerto write something here or to contact authors.