mysql - Duplicate entry '0' for key 'PRIMARY' -


i don't understand why i'm getting error when trying populate table. there nothing in table @ moment don't understand why there duplicate...

this code i'm using:

insert suppliers (supp_id,company_name,town,phone) values ("adt217","adtec","birmingham","0121-368-1597"), ("cps533","cps","maidenhead","01382-893715"), ("fcl162","forcomp ltd","nottingham","01489-133722"), ("kbc355","kbc computers","glasgow","0141-321-1497"); 

any appreciated,

thank you.

suppliers table...

create table suppliers(     supp_id int not null,     company_name character(15) not null,     town character(15)     phone character(15) primary key(supp_id) ); 

this occurs when have primary key not give initialization value. insert causing duplication.

in case, 2 possibilities come mind:

  1. supp_id primary key , declared number. in older versions of mysql, think string values silently converted numbers. because leading characters letters, value 0.

  2. you have id field primary key, given no value , not declared auto_increment.

edit:

i suspect want following code:

create table suppliers (     supplierid int not null auto_increment primary key,     supp_name varchar(255) unique,     company_name varchar(15) not null,     town varchar(15),     phone varchar(15) );  insert suppliers(supp_name, company_name, town, phone)     values ('adt217', 'adtec', 'birmingham', '0121-368-1597'),            ('cps533', 'cps', 'maidenhead', '01382-893715'),            ('fcl162', 'forcomp ltd', 'nottingham', '01489-133722'),            ('kbc355', 'kbc computers', 'glasgow', '0141-321-1497'); 

some notes:

  • usually want varchar() rather char(), unless lots of spaces @ end of strings.
  • i added unique supplier name table , declared id auto_increment.
  • single quotes ansi standard string constants. mysql (and other databases) allow double quotes, there no reason not use standard.

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -