I want to add records to the table but there is a duplicate

51 Views Asked by At

I have a table named Car and I want to add this records;

insert into Car 
values 
 ('a', 'a'), ('a', 'b'), ('a', 'c'),('b', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'd');

I got this massage: ( ERROR 1062 (23000): Duplicate entry 'a' for key a)

so how I can fix it?

1

There are 1 best solutions below

0
On BEST ANSWER

You have defined either a Primary Key or a Unique Key on the first column of the Car table. Either redefine the table without the Primary Key or Drop the Index. See demo here.
Another possibility is that you intended the unique key to be a composite of the two fields, in which case you need to amend your CREATE UNIQUE INDEX, as also shown in the demo.