mysql工作台创建表时出现错误1064

tktrz96b  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(323)

我正在尝试将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.

上面看到的代码是使用“createtable”工作台特性生成的。

wmomyfyw

wmomyfyw1#

我用int(10)代替int来解决这个问题

ID INT(10)

ID INT
6tqwzwtp

6tqwzwtp2#

UNSIGNED 以及 INT 一起走,这样就行了:

`ID` INT  UNSIGNED UNIQUE NOT NULL AUTO_INCREMENT,

这个比较短:

`ID` INT  UNSIGNED AUTO_INCREMENT PRIMARY KEY,

主键已为非- NULL 以及 unique . 不需要两次声明这些属性。

相关问题