1.7.3.1 PRIMARY KEY and UNIQUE Index ConstraintsPRIMARY KEY和UNIQUE索引约束

Normally, errors occur for data-change statements (such as INSERT or UPDATE) that would violate primary-key, unique-key, or foreign-key constraints. 通常,数据更改语句(如INSERTUPDATE)会出现违反主键、唯一键或外键约束的错误。If you are using a transactional storage engine such as InnoDB, MySQL automatically rolls back the statement. 如果您使用的是事务存储引擎,如InnoDB,MySQL会自动回滚该语句。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将停止处理发生错误的行的语句,并保留未处理的任何剩余行。

MySQL supports an IGNORE keyword for INSERT, UPDATE, and so forth. MySQL支持IGNORE关键字用于INSERTUPDATE等。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.6, “INSERT Statement”, Section 13.2.13, “UPDATE Statement”, and so forth).<如果使用它,MySQL将忽略主键或唯一键冲突,并继续处理下一行。请参阅您正在使用的语句部分(第13.2.6节,“INSERT语句”第13.2.13节,“UPDATE语句”等)。

You can get information about the number of rows actually inserted or updated with the mysql_info() C API function. 您可以通过mysql_info()C API函数获取实际插入或更新的行数信息。You can also use the SHOW WARNINGS statement. 您也可以使用SHOW WARNINGS语句。See mysql_info(), and Section 13.7.7.42, “SHOW WARNINGS Statement”.请参阅mysql_info()第13.7.7.42节,“SHOW WARNINGS语句”

InnoDB and NDB tables support foreign keys. See Section 1.7.3.2, “FOREIGN KEY Constraints”.InnoDBNDB表支持外键。参见第1.7.3.2节,“FOREIGN KEY约束”