mysql - ""Duplicate Entry" while inserting in a Composite primary keyed table -
create table if not exists `mytable` ( `machine_no` varchar(50) character set ascii not null, `date` datetime not null, `nature` int(11) default null, `start` time not null, primary key (`machine_no`,`date`), unique key `date` (`date`), unique key `start` (`start`), unique key `start_2` (`start`), unique key `nature` (`nature`) ) engine=innodb default charset=latin1;
this table has composite key.
when try insert 2 records same date/time different value of machine_no. says duplicate entry date. dont understand reason it. composite key, should duplicate entry in both attributes.
your primary key
works fine:
primary key (`machine_no`,`date`),
what causes issue unique key
have:
unique key `date` (`date`),
this not allow 2 rows same datetime inserted.
similarly other 3 unique keys cause torubles well:
unique key `start` (`start`), unique key `start_2` (`start`), unique key `nature` (`nature`)
so, make keys simple (not unique).
and there no reason have 2 identical keys differ in name (start
, start_2
)
Comments
Post a Comment