2013-01-14 40 views
0

以下代码是备份脚本(可能使用mysqldump)生成的较大查询中的一个最小示例。它导致错误,我不知道为什么。谁可以帮忙?备份脚本中的错误查询导致错误1064

CREATE TABLE `tl_custom_tandem_lang` (
    `id` varchar(2) COLLATE latin1_german2_ci NOT NULL, 
    PRIMARY_KEY (`id`), 
    UNIQUE KEY `id` (`id`) 
); 

主要生产以下错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(id), UNIQUE KEY id (id))' at line 3

回答

4

应该是PRIMARY KEYPRIMARY_KEY删除下划线使它工作

CREATE TABLE `tl_custom_tandem_lang` 
(
    `id` varchar(2) COLLATE latin1_german2_ci NOT NULL, 
    PRIMARY KEY (`id`), 
    UNIQUE KEY `tb_unique` (`id`) 
); 
+2

不错。接得好! – Pedigree

0

删除UNIQUE KEY一样在此之后, 'ID':

CREATE TABLE `tl_custom_tandem_lang` (
    `id` varchar(2) COLLATE latin1_german2_ci NOT NULL, 
    PRIMARY_KEY (`id`), 
    UNIQUE KEY (`id`) 
); 
+0

我为什么要那样做?我认为它使关键字成为一个名字,所以我可以在以后参考它,不是吗? – hielsnoppe