
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- What will happen, if we did not have cartilage in our body?
- If we don't have bones or we lose our any one bone, so what will happen?
- What would happen if we insert empty values in a table with a column set as type TIMESTAMP CURRENT_TIMESTAMP?
- What will happen if we directly call the run() method in Java?
- If our joints will not move what will happen?
- MySQL UNIQUE declaration to avoid inserting duplicate values?
- What happens if I will add a UNIQUE constraint on the same column for multiple times?
- What will happen when metals react with acids?
- What will happen if we pull the yarn from a torn pair of socks? Why so?
- Can we fetch multiple values with MySQL WHERE Clause?
- Python Pandas – Find unique values from multiple columns
- How can we get only unique values of a column in MySQL result set?
- What will happen if a semicolon is misplaced in JavaScript?
- What will happen if garbage is left open in bin?
- Group with multiple fields and get the count of duplicate field values grouped together in\nMongoDB

Advertisements