-1

我正在使用 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

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

4

3 回答 3

2

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

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语句中的所有三个出现添加此内容。

于 2012-07-02T11:57:25.523 回答
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;
于 2012-07-02T11:58:10.570 回答
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;
于 2012-07-02T11:59:57.870 回答