DuplicatekeyerrorinMySQL (Duplicatekeyname & amp; #39; &

Source: Internet
Author: User
Thebelowqueryisresultinginanerror. IcreatedthisqueryinMySQLWorkbenchErrorSQLquery: Partition Table 'smsdb'. 'intsupervisor '-----------------------------------------------------

The below query is resulting in an error. I created this query in MySQL Workbench ErrorSQL query: -- Optimize Table 'smsdb'. 'intsupervisor '-----------------------------------------------------

The below query is resulting in an error. I created this query in MySQL Workbench

ErrorSQL query:-- ------------------------------------------------------- Table `smsdb`.`IntSupervisor`-- -----------------------------------------------------  CREATE TABLE IF NOT EXISTS `smsdb`.`IntSupervisor` (   `int_supr_id` VARCHAR( 32 ) NOT NULL ,   `cent_id` INT NOT NULL ,   INDEX `fk_IntSupervisor_Person1_idx` ( `int_supr_id` ASC ) ,   INDEX `fk_IntSupervisor_Center1_idx` ( `cent_id` ASC ) ,   PRIMARY KEY ( `int_supr_id` ) ,   CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )    REFERENCES `smsdb`.`Staff` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT ,   CONSTRAINT `fk_center_id` FOREIGN KEY ( `cent_id` )   REFERENCES  `smsdb`.`Center` (`cent_id` ) ON DELETE CASCADE ON UPDATE RESTRICT ) ENGINE = InnoDB;

I got an error message on execution:

MySQL said: Documentation      #1022 - Can't write; duplicate key in table 'intsupervisor'

If anyone has any ideas on how I can resolve this issue, please guide me in the right direction. Thanks!

Welcome to relational databases in MySQL! ;)

You can't have two foreign keys named the same thing about ss the whole query.

PRIMARY KEY ( `int_supr_id` ) ,
CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` ) 

In the above statement, you can't redefine the index type on a single column.

So, how do I fix this annoying error?

Based on the structure of the database, you need to remove one of the two lines above. i'm guessing your linking to another table from the one you are creating, so I recommend replacing...

PRIMARY KEY ( `int_supr_id` ) ,       CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )

With the following:

CONSTRAINT `fk_parent_id` FOREIGN KEY ( `int_supr_id` )

(If the above doesn't work, you likely need to specify a table name for the foreign key)


2 .--
-- Table structure for table 'payment'
--


Drop table if exists 'payment ';
SET @ saved_cs_client =@@ character_set_client;
SET character_set_client = utf8;
Create table 'payment '(
'Id' bigint (20) not null AUTO_INCREMENT,
'Entry _ id' int (11) not null,
'Account _ id' int (11) not null,
'Amount 'double not null,
'Pmt _ form' varchar (20) not null,
'Reference' varchar (120) default null,
'Coid' int (11) not null,
Primary key ('id '),
Unique key 'id' ('id '),
KEY 'fk _ PAYMENT_ACCOUNT '('account _ id '),
KEY 'fk _ PAYMENT_ENTRY '('entry _ id '),
CONSTRAINT 'fk _ PAYMENT_ACCOUNT 'foreign key ('account _ id') REFERENCES 'account' ('id '),
CONSTRAINT 'fk _ PAYMENT_ENTRY 'foreign key ('entry _ id') REFERENCES 'register _ entry' ('id ')
) ENGINE = InnoDB AUTO_INCREMENT = 1 default charset = utf8;
SET character_set_client = @ saved_cs_client;

The first one is entry_ID and the first one is entry_id, causing an error. Later, the data is imported in the same way.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.