Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 35.4Mb
PDF (A4) - 35.5Mb
PDF (RPM) - 34.5Mb
EPUB - 8.7Mb
HTML Download (TGZ) - 8.5Mb
HTML Download (Zip) - 8.5Mb
HTML Download (RPM) - 7.3Mb
Eclipse Doc Plugin (TGZ) - 9.3Mb
Eclipse Doc Plugin (Zip) - 11.5Mb
Man Pages (TGZ) - 201.5Kb
Man Pages (Zip) - 306.8Kb
Info (Gzip) - 3.3Mb
Info (Zip) - 3.3Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  /  ...  /  PRIMARY KEY and UNIQUE Index Constraints

1.8.3.1 PRIMARY KEY and UNIQUE Index Constraints

Normally, errors occurs for data-change statements (such as INSERT or UPDATE) that would violate primary-key, unique-key, or foreign-key constraints. If you are using a transactional storage engine such as InnoDB, 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 an IGNORE keyword for INSERT, 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 14.2.5, “INSERT Syntax”, Section 14.2.11, “UPDATE Syntax”, and so forth).

You can get information about the number of rows actually inserted or updated with the mysql_info() C API function. You can also use the SHOW WARNINGS statement. See Section 25.8.7.36, “mysql_info()”, and Section 14.7.5.40, “SHOW WARNINGS Syntax”.

InnoDB and NDB tables support foreign keys. See Section 1.8.3.2, “FOREIGN KEY Constraints”.


User Comments
  Posted by hamy t on January 4, 2009
Quick Example of ignoring a unique key

Here is our table:
CREATE TABLE `file_names` (
`id` int(11) NOT NULL auto_increment,
`file_name` text NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `file_name` (`file_name`(200))
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

Here is our query
INSERT IGNORE INTO `its_streamingdata`.`file_names` (`id` ,
`file_name`) VALUES (NULL , 'a'), (NULL , 'a')

The table now contains one row with a filename of 'a'

HTH
Hamy
  Posted by DBA Lead on February 21, 2012
Sign Up Login You must be logged in to post a comment.