无法在Mysql数据库中创建表

时间:2013-03-13 04:25:50

标签: mysql sql database

我正在尝试使用下面的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

但获取错误代码:1022。无法写入;表'tamilword_secondary'中的重复键。

感谢您帮助我..我已经有了表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 个答案:

答案 0 :(得分:0)

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

请参阅SQL Fiddle example