duplicate entry

Solutions on MaxInterview for duplicate entry by the best coders in the world

showing results for - "duplicate entry"
Moritz
05 Sep 2018
1The main reason why the error has been generated is because there is already an existing value of 1 for the column ID in which you define it as PRIMARY KEY (values are unique) in the table you are inserting.
2
3Why not set the column ID as AUTO_INCREMENT?
4
5CREATE  TABLE IF NOT EXISTS `PROGETTO`.`UFFICIO-INFORMAZIONI` (
6  `ID` INT(11) NOT NULL AUTO_INCREMENT,
7  `viale` VARCHAR(45) NULL ,
8   .....
9and when you are inserting record, you can now skip the column ID
10
11INSERT INTO `PROGETTO`.`UFFICIO-INFORMAZIONI` (`viale`, `num_civico`, ...) 
12VALUES ('Viale Cogel ', '120', ...)
Miranda
11 Mar 2019
1# The main Reason you are grtting this error is because 
2#there is a unque flag on the field. lets see an example
3
4# CREATE A NEW TABLE CALLED User;
5CREATE TABLE User(
6  # this will not trigger duplicates because of the auto_increment option
7  id int unsigned primary key auto_increment 
8  name VARCHAR(255) not null,
9  # this field will always trigger the error if you leave it empty or if you
10  # insert a user with same email as the one in the table already. 
11  email VARCHRA(255) unique 
12  )
13  # INSERT DAta INTO THE TABLE.
14  INSERT INTO User(name, email) VALUES('Sample Name','sample@example.com') # This will pass
15
16  INSERT INTO User(name, email) VALUES('Sample2 Name','sample@example.com')   # This will not pass
17  # the second insert query will yield an error because the email already exists in the database. 
18  # to avoid this error make sure that the unique field is always checked before insert into the table.
19                  
20