【问题标题】: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 'PRIMERY KEY您的 SQL 语法有误;查看与您的 MySQL 服务器版本对应的手册,了解在 \'PRIMERY KEY 附近使用的正确语法
【发布时间】:2023-02-05 09:58:48
【问题描述】:

我使用以下代码在 MySQL 上创建了一个表:

CREATE TABLE IF NOT EXISTS auth (
  id INT AUTO_INCREMENT,
  email VARCHAR(50) UNIQUE NOT NULL PRIMERY KEY,
  password VARCHAR(250) NOT NULL,
  username VARCHAR(50) UNIQUE,
  admin BOOLEAN NOT NULL DEFAULT 0,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

但是我得到了这个错误:

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 'PRIMERY KEY,
  password VARCHAR(250) NOT NULL,
  username VARCHAR(50) UNIQUE,

问题是什么?

【问题讨论】:

    标签: mysql syntax primary-key create-table


    【解决方案1】:

    如果我没记错的话你打错了首要的关键所以应该是首要的关键

    CREATE TABLE IF NOT EXISTS auth (
      id INT AUTO_INCREMENT,
      email VARCHAR(50) UNIQUE NOT NULL PRIMARY KEY,
      password VARCHAR(250) NOT NULL,
      username VARCHAR(50) UNIQUE,
      admin BOOLEAN NOT NULL DEFAULT 0,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-14
      • 2015-03-30
      • 2022-06-14
      • 1970-01-01
      • 1970-01-01
      • 2021-08-06
      • 2022-12-12
      • 1970-01-01
      相关资源
      最近更新 更多