![]() If the record is a duplicate, then the IGNORE keyword tells MySQL to discard it silently without generating an error. If a record doesn't duplicate an existing record, then MySQL inserts it as usual. Use the INSERT IGNORE command rather than the INSERT command. ![]() The presence of a unique index in a table normally causes an error to occur if you insert a record into the table that duplicates an existing record in the column or columns that define the index. When you do this, it is also necessary to declare the indexed columns to be NOT NULL, because a PRIMARY KEY does not allow NULL values − To prevent multiple records with the same first and last name values from being created in this table, add a PRIMARY KEY to its definition. ![]() Let us take an example – The following table contains no such index or primary key, so it would allow duplicate records for first_name and last_name. You can use a PRIMARY KEY or a UNIQUE Index on a table with the appropriate fields to stop duplicate records. Preventing Duplicates from Occurring in a Table This chapter will describe how to prevent the occurrence of duplicate records in a table and how to remove the already existing duplicate records. It is required to identify duplicate records and remove them from the table. Most of the times it is allowed but sometimes it is required to stop duplicate records. Generally, tables or result sets sometimes contain duplicate records. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |