mysql - Duplicate entry key for key primary -
i have encountered error on codes. says
error code 1062, sql state 23000: duplicate entry '88889' key 'primary' line 15, column 1
error code 1062, sql state 23000: duplicate entry '87990' key 'primary' line 20, column 1
error code 1062, sql state 23000: duplicate entry '79678' key 'primary' line 25, column 1
error code 1062, sql state 23000: duplicate entry '88799' key 'primary' line 30, column 1
error code 1062, sql state 23000: duplicate entry '78998' key 'primary' line 35, column 1
and here code:
create table if not exists studentrecord ( student_id varchar(7), stud_first_name varchar(15) not null, stud_last_name varchar(15) not null, stud_date_of_birth date not null, stud_address varchar(50) not null, stud_program varchar(20) not null, stud_marital_status int(2) not null, stud_country varchar(20) not null, primary key (student_id) ) engine=innodb; -- insert sample data insert studentrecord values( '88889','albukori','zaman khan','1969-07-08', '4-5, dead wood street 5, 12000 sintok, kedah','msc. it', '1','malaysia'); insert studentrecord values( '87990','haslina','mahathir','1970-11-12', '345, new smart village, 17100 nilai, n. sembilan','msc. ict', '2','malaysia'); insert studentrecord values( '79678','mohammed','fajr','1975-04-20', 'pearl apt, level 10, al-hijr, 45200 abu dhabi','msc. expert system', '2','uea'); insert studentrecord values( '88799','mustar','mohd dali','1979-06-24', '345, side village, kerian, 12300 jawa barat','msc. multimedia', '1','indonesia'); insert studentrecord values( '78998','satkorn','chengmo','1968-01-26', '34 uptown street #4, tech park, 78100 bangkok','msc. it', '2','thailand');
thanks response. hope me, im new this
that code can run once, system trying enter same records twice , failing. sounds table studentrecord has primary key first value trying enter e.g.78998
to around can make code reentrant changing (please bear in mind t-sql not mysql)
if not exists (select * studentrecord id = 1878998) insert studentrecord values( '78998','satkorn','chengmo','1968-01-26', '34 uptown street #4, tech park, 78100 bangkok','msc. it', '2','thailand');
edit: sasha salauyou says, can drop table first
Comments
Post a Comment