user10570640
user10570640

Reputation:

MySQL Workbench Error 1064 when creating table

I am trying to use MySQL Workbench 8.0.3 with MariaDB but I get the following error:

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.

The code you see above has been generated using the "Create Table" Workbench feature.

Upvotes: 2

Views: 3133

Answers (2)

user10570640
user10570640

Reputation:

I solved it by using int(10) instead of int

ID INT(10)

not

ID INT

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270873

UNSIGNED and INT go together, so this works:

`ID` INT  UNSIGNED UNIQUE NOT NULL AUTO_INCREMENT,

This is shorter:

`ID` INT  UNSIGNED AUTO_INCREMENT PRIMARY KEY,

A primary key is already non-NULL and unique. There is no need to declare those properties twice.

Upvotes: 1

Related Questions