无法在Mysql数据库中创建表

时间:2021-12-31 00:50:44

I am trying to create table in Mysql database with the below sql

我试图用下面的sql在Mysql数据库中创建表

   CREATE  TABLE IF NOT EXISTS `dev_dict`.`TAMILWORD_SECONDARY` (
    `ID` INT NOT NULL ,
    `TAMILWORD_ID` INT NOT NULL ,
    `WORDS` VARCHAR(50) NOT NULL ,
    `CREATED_DTTM` TIMESTAMP NOT NULL ,
    `MODIFIED_DTTM` TIMESTAMP NOT NULL ,
     PRIMARY KEY (`ID`) ,
       UNIQUE INDEX `WORDS_UNIQUE` (`WORDS` ASC, `TAMILWORD_ID` ASC) ,
       INDEX `FK_TAMILWORD_ID_idx` (`TAMILWORD_ID` ASC) ,
     CONSTRAINT `FK_TAMILWORD_ID`
       FOREIGN KEY (`TAMILWORD_ID` )
       REFERENCES `dev_dict`.`TAMILWORD` (`ID` )
       ON DELETE NO ACTION
     ON UPDATE NO ACTION)
    ENGINE = InnoDB

but getting Error Code: 1022. Can't write; duplicate key in table 'tamilword_secondary'.

但得到错误代码:1022。不能写;表'tamilword_secondary'中的重复键。

thanks for helping me.. i have the table tamilword already , and getting same error

谢谢你帮助我..我已经有了表tamilword,并得到同样的错误

   CREATE  TABLE IF NOT EXISTS `dev_dict`.`TAMILWORD` (
     `ID` INT NOT NULL ,
     `WORD` VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NOT NULL ,
     `SENTENCE` VARCHAR(100) NULL ,
     `CREATED_DTTM` TIMESTAMP NOT NULL ,
    `MODIFIED_DTTM` TIMESTAMP NOT NULL ,
     PRIMARY KEY (`ID`) ,
        INDEX `SECONDARY` (`WORD` ASC, `SENTENCE` ASC) )
     ENGINE = InnoDB

1 个解决方案

#1


0  

Create dev_dict.TAMILWORD table first. Other than that your statement works.

首先创建dev_dict.TAMILWORD表。除此以外你的陈述有效。

See SQL Fiddle example

请参见SQL小提琴示例

#1


0  

Create dev_dict.TAMILWORD table first. Other than that your statement works.

首先创建dev_dict.TAMILWORD表。除此以外你的陈述有效。

See SQL Fiddle example

请参见SQL小提琴示例