Followers

Monday, 30 March 2015

Using IGNORE with MySQL to prevent duplicate key errors

Table sets sometimes contain duplicate records. it is required to identify duplicate data and remove them in table. This chapter will describe how to prevent duplicate data occurring in a table and how to remove already existing duplicate data.


CREATE TABLE table
(
    first_name CHAR(20),
    last_name CHAR(20),
    sex CHAR(10)
);

we can use a UNIQUE Index or PRIMARY KEY on a table with appropriate fields to stop duplicate data.

INSERT IGNORE  INTO TABLE SET first_name='robin', last_name='jonson' , sex='male';

No comments:

Post a Comment