【问题标题】:Syntax error creating MySQL table创建 MySQL 表的语法错误
【发布时间】:2014-05-17 08:56:13
【问题描述】:

也许我对 Postgres 太习惯了,但为什么会出现这个错误

您的 SQL 语法有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 '{ id int not null AUTO_INCREMENT, email varchar(100) not null, 主键(第 1 行的 id'

什么时候运行?

create table `users`{
    id int not null AUTO_INCREMENT,
    email varchar(100) not null,
    primary key(id)
};

【问题讨论】:

  • 使用括号 CREATE TABLE Users ( ... ) 而不是大括号 CREATE TABLE Users { ... }
  • 用 () 代替 {}
  • 该语法对 Postgres 也无效。

标签: mysql sql


【解决方案1】:

正确的语法是:

创建 TABLE 用户(
id INT NOT NULL AUTO_INCREMENT,
电子邮件 VARCHAR(100) NOT NULL,
主键(id) );

在这里查看您的版本:

https://dev.mysql.com/doc/refman/4.1/en/creating-tables.html

【讨论】:

    【解决方案2】:

    使用圆括号(普通括号)() 而不是大括号:

    create table `users` (
        id int not null AUTO_INCREMENT,
        email varchar(100) not null,
        primary key(id)
    );
    

    【讨论】:

      猜你喜欢
      • 2014-04-09
      • 2016-02-07
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      相关资源
      最近更新 更多