Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 35.1Mb
PDF (A4) - 35.2Mb
Man Pages (TGZ) - 256.4Kb
Man Pages (Zip) - 361.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  / ...  / General Information  / MySQL Standards Compliance  / How MySQL Deals with Constraints  /  PRIMARY KEY and UNIQUE Index Constraints

1.6.3.1 PRIMARY KEY and UNIQUE Index Constraints

Normally, errors occur for data-change statements (such asINSERT orUPDATE) that would violate primary-key, unique-key, or foreign-key constraints. If you are using a transactional storage engine such asInnoDB, MySQL automatically rolls back the statement. If you are using a nontransactional storage engine, MySQL stops processing the statement at the row for which the error occurred and leaves any remaining rows unprocessed.

MySQL supports anIGNORE keyword forINSERT,UPDATE, and so forth. If you use it, MySQL ignores primary-key or unique-key violations and continues processing with the next row. See the section for the statement that you are using (Section 13.2.5, “INSERT Statement”,Section 13.2.11, “UPDATE Statement”, and so forth).

You can get information about the number of rows actually inserted or updated with themysql_info() C API function. You can also use theSHOW WARNINGS statement. Seemysql_info(), andSection 13.7.5.40, “SHOW WARNINGS Statement”.

InnoDB andNDB tables support foreign keys. SeeSection 1.6.3.2, “FOREIGN KEY Constraints”.