- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What will happen if we have set UNIQUE and multiple insertion with duplicate values
An error will arise and nothing will get inserted in the table Let us see an example and create a table −
mysql> create table DemoTable1585 -> ( -> StudentId int, -> StudentMarks int, -> UNIQUE(StudentId) -> ); Query OK, 0 rows affected (1.02 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1585 values(1,87),(2,98),(3,91),(3,48); ERROR 1062 (23000): Duplicate entry '3' for key 'StudentId'
Display all records from the table using select statement −
mysql> select * from DemoTable1585;
This will produce the following output. Nothing gets inserted:
Empty set (0.00 sec)
Advertisements