Duplicacy can be attained when inserting many records into the database. Adding a Primary key constraint to a column restricts the insertion of duplicate values. This action gives an error message in the console and can interrupt the operation flow. The IGNORE statement in SQL works the same way but does not interrupt the flow of operation. It just generates only a warning message if any duplicate values get added.
- Syntax to IGNORE Statement –
INSERT IGNORE INTO table_name (column1,column2,....,columnN)
VALUES (value1,value2,....,value3);
Demo Table –
Science_Students Table
Student_id | Student_name | Address | Phone_number | Age | Grade |
1 | Simon | Chicago | 5687466 | 18 | A+ |
2 | Alvin | Mexico | 6321478 | 19 | A+ |
3 | Theo | Paris | 3362473 | 18 | B |
4 | Brittany | Newyork | 6632147 | 19 | C |
5 | Jenette | Chicago | 9211627 | 16 | A+ |
6 | Jerry | Beverly Hills | 3652877 | 18 | F |
Example – In this Demo table, we have “Student_id” as the Primary key. Try to insert a duplicate value to the “Student_id” and use SQL IGNORE Statement to see the result.
INSERT IGNORE INTO Science_Students (Student_id, Student_name,Address, Phone_number , Age,Grade ) VALUES(1, 'Simon', 'Chicago' , '5687466' , 18 , 'A+');
- This value won’t be inserted in the table because “Student_id = 1” has been inserted in the table and inserting it again violates the primary key constraints.
The output after implementing the above IGNORE Statement –
No entry inserted. |
Follow us on Twitter, Facebook, Linkedin, and Tableau Public to stay updated with our latest blog and what’s new in Tableau.
If you are looking forward to getting your data pipeline built and setting up the dashboard for business intelligence, book a call now from here.
#analytics #data #business #artificialintelligence #machinelearning #startup #deeplearning #deeplearning #datascience #ai #growth #dataanalytics #india #datascientist #powerbi #dataanalysis #tableau #SQL #businessanalytics #businessanalyst #businessandmanagement #dataanalyst #businessanalysis #analyst #analysis #powerbideveloper #powerbidesktop #letsviz