执行SQL命令以创建表时出错

时间:2012-07-02 11:54:50

标签: mysql mysql-error-1064

我正在使用Mysql-query-browser(来自mysql.com的mysql gui)创建一个表。

CREATE TABLE `mydb`.`mytable` (
`client` INT(11) UNSIGNED NOT NULL,
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR NOT NULL,
`description` VARCHAR NOT NULL,
`url` VARCHAR NOT NULL,
`keywords` TEXT NOT NULL,
PRIMARY KEY(`id`)
)
ENGINE = MYISAM;

但我不断收到以下错误消息:

Error executing SQL commands to create table.

  MySQL Error Nr. 1064 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
 'NOT NULL,`description` VARCHAR NOT NULL,`url` VARCHAR NOT NULL,`keywo' at line 4

如果有人知道如何解决它? 请帮我。 感谢

3 个答案:

答案 0 :(得分:2)

如果将列定义为varchar,则必须将条目的最大长度添加到该列(请参阅MySQL docu)。因此,在您的示例中,可能会导致以下结果:

CREATE TABLE `mydb`.`mytable` (
`client` INT(11) UNSIGNED NOT NULL,
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(50) NOT NULL,
`description` VARCHAR(100) NOT NULL,
`url` VARCHAR(100) NOT NULL,
`keywords` TEXT NOT NULL,
PRIMARY KEY(`id`)
)
ENGINE = MYISAM;

请注意,您必须在语句中为varchar的所有三次出现添加此项。

答案 1 :(得分:0)

您必须为VARCHAR TYPE指定长度

   CREATE TABLE `test_model`.`mytable` (
    `client` INT(11) UNSIGNED NOT NULL,
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `title` VARCHAR(50) NOT NULL,
    `description` VARCHAR(50) NOT NULL,
    `url` VARCHAR(50) NOT NULL,
    `keywords` TEXT NOT NULL,
    PRIMARY KEY(`id`)
    )
    ENGINE = MYISAM;

答案 2 :(得分:0)

指定varchar的大小应该可以解决问题:

CREATE TABLE `mydb`.`mytable` (
`client` INT(11) UNSIGNED NOT NULL,
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(20) NOT NULL,
`description` VARCHAR(20) NOT NULL,
`url` VARCHAR(20) NOT NULL,
`keywords` TEXT NOT NULL,
PRIMARY KEY(`id`)
)
ENGINE = MYISAM;