创建表时出现MySQL Workbench错误1064

时间:2018-11-08 19:48:54

标签: mysql sql mariadb

我正在尝试将MySQL Workbench 8.0.3与MariaDB结合使用,但出现以下错误:

Executing:

CREATE TABLE `mydb`.`customer` (

  `ID` INT UNIQUE UNSIGNED NOT NULL AUTO_INCREMENT,

  `Name` VARCHAR(255) NOT NULL,

  `Email` VARCHAR(255) CHARACTER SET 'utf8' NOT NULL,

  `Street` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,

  `City` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,

  PRIMARY KEY (`ID`));


ERROR 1064: You have an error in your SQL syntax; check the manual that     
corresponds to your MariaDB server version for the right syntax to use near 'UNSIGNED NOT NULL AUTO_INCREMENT,
  `Name` VARCHAR(255) NOT NULL,
  `Email` VARC' at line 2
SQL Statement:
CREATE TABLE `mydb`.`customer` (
  `ID` INT UNIQUE UNSIGNED NOT NULL AUTO_INCREMENT,
  `Name` VARCHAR(255) NOT NULL,
  `Email` VARCHAR(255) CHARACTER SET 'utf8' NOT NULL,
  `Street` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
  `City` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
  PRIMARY KEY (`ID`))

Operation failed: There was an error while applying the SQL script to the database.

上面看到的代码是使用“创建表”工作台功能生成的。

使用PHP / mySQLli时出现相同错误

已解决修改:

 ID INT(10)

不是

 ID INT

2 个答案:

答案 0 :(得分:1)

UNSIGNEDINT一起使用,因此可行:

`ID` INT  UNSIGNED UNIQUE NOT NULL AUTO_INCREMENT,

这更短:

`ID` INT  UNSIGNED AUTO_INCREMENT PRIMARY KEY,

主键已经不是NULLunique了。无需两次声明这些属性。

答案 1 :(得分:0)

我通过使用int(10)而不是int

解决了该问题
    var A+ = 4.0;
    var A = 4.0;
    var A- = 3.67;

不是

ID INT(10)