![]() ![]() ![]() We can see that 12 rows got inserted when in reality we tried to insert 13 rows but as Raj record was duplicated all the remaining rows got inserted successfully. Let us retrieve the records of the developers table and check which records got inserted using the following query – The warning shows that there was one record with the name Raj that had duplicate value for the name column having a unique constraint on it. To see the warning we can execute the following command – We can see that 12 rows were affected and the query got executed with one warning. INSERT IGNORE INTO `developers` (`team_id`, `name`, `position`, `technology`, `salary`) VALUES Let us now try to insert the records by using the INSERT IGNORE statement instead of the INSERT statement. We can see that none of the records got inserted even though other than the record with the Raj name were correct. Let us retrieve the records of the developer’s table by using the following query statement INSERT INTO `developers` (`team_id`, `name`, `position`, `technology`, `salary`) VALUES We can try executing the following query statement – In this case, all other columns that we have mentioned in our insert query were correct as per all the constraints and restrictions were also not inserted. As inserting such records is against the rules and breaking the constraint MySQL will issue an error saying the record with a duplicate value of name column cannot be inserted. Now, we will try to insert multiple records having a single record value repeated for the name column on which we have defined the unique constraint to avoid insertion of records with the same name. `developer_id` int(11) AUTO_INCREMENT PRIMARY KEY, ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |