#1064您的SQL语法有错误;

时间:2014-08-28 08:57:48

标签: mysql phpmyadmin mysql-error-1064

当我尝试在SQL中创建TABLE时,我收到以下错误。

phpMyAdmin的版本我使用它4.2.7.1,它说它是最新的。

有人可以帮忙吗?我无法发现错误?我查看了与错误1064相关的类似问题,但没有快乐

CREATE TABLE 'categories' (
'id' SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
'category' VARCHAR(45) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE INDEX 'category_UNIQUE' ('category' ASC)
) ENGINE = InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE 'orders' (
    'id' INT UNSIGNED NOT NULL AUTO_INCREMENT,
    'users_id' INT UNSIGNED NOT NULL,
    'transaction_id' VARCHAR(45) NOT NULL,
    'payment_status' VARCHAR(45) NOT NULL,
    'payment_amount' INT UNSIGNED NOT NULL,
    'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
   PRIMARY KEY ('id'),
    INDEX 'date_created' ('date_created' ASC),
    INDEX 'transaction_id' ('transaction_id' ASC),
    CONSTRAINT 'fk_orders_users1' FOREIGN KEY ('id')     
        REFERENCES 'users' ('id')
        ON DELETE NO ACTION ON UPDATE NO ACTION
    ) ENGINE = InnoDB DEFAULT CHARSET=utf8;

    CREATE TABLE 'pages' (
        'id' INT UNSIGNED NOT NULL AUTO_INCREMENT,
        'categories_id' SMALLINT UNSIGNED NOT NULL,
        'title' VARCHAR(100) NOT NULL,
        'description' TINYTEXT NOT NULL,
        'content' LONGTEXT NULL,
        'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
       PRIMARY KEY ('id'),
        INDEX 'date_created' ('date_created' ASC),
        INDEX 'fk_pages_categories_idx' ('categories_id')
            REFERENCES 'categories' ('id')
            ON DELETE NO ACTION ON UPDATE NO ACTION

     ) ENGINE = InnoDB DEFAULT CHARSET=utf8;

  CREATE TABLE 'pdfs' (
      'id' INT UNSIGNED NOT NULL AUTO_INCREMENT,
      'title' VARCHAR (100) NOT NULL,
      'description' TINYTEXT NOT NULL,
      'tmp_name' CHAR(63) NOT NULL,
      'file_name' VARCHAR(100) NOT NULL,
      'size' MEDIUMINT UNSIGNED NOT NULL,
      'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY ('id')
      UNIQUE INDEX 'tmp_name_UNIQUE' ('tmp_name' ASC),
      INDEX 'date_created' ('date_created' ASC)
    ) ENGINE = InnoDB DEFAULT CHARSET=utf8;

    CREATE TABLE ('users')
    'id' INT UNSIGNED NOT NULL AUTO_INCREMENT,
    'type' ENUM('member','admin') NOT NULL DEFAULT 'member'
    'username' VARCHAR(45) NOT NULL,
    'email' VARCHAR(80) NOT NULL,
    'pass' VARCHAR(255) NOT NULL,
    'first_name' VARCHAR (45) NOT NULL,
    'last_name' VARCHAR (45) NOT NULL,
    'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    'date_expires' DATE NOT NULL,
    'date_modified' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
      PRIMARY KEY ('id'),
      UNIQUE INDEX 'username_UNIQUE' ('username' ASC),
      UNIQUE INDEX 'email_UNIQUE' ('email' ASC),
        INDEX 'login' ('email' ASC, 'pass' ASC)
      ) ENGINE = InnoDB DEFAULT CHARSET=utf8;

MySQL说:文档

#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 ''categories' (
    'id' SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
    'catego' at line 1

3 个答案:

答案 0 :(得分:2)

从字段名称中删除单引号字符

答案 1 :(得分:1)

你需要使用back-ticks`(键盘上的1键旁边)而不是'引号。这对我有用:

CREATE TABLE `categories` (
   `id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
   `category` VARCHAR(45) NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE INDEX `category_UNIQUE` (`category` ASC)
) ENGINE = InnoDB DEFAULT CHARSET=utf8;

答案 2 :(得分:1)

用'。

替换'表名和字段名周围的'字符

然后会出现更多语法错误 - 例如,'users'表周围有不需要的括号。 此外,当您创建“订单”表时,它在用户上有一个外键,但稍后会声明用户。