简体   繁体   中英

MYSQL: You have an error in your SQL syntax

I'm having trouble with this SQL statement

CREATE TABLE users
(
  'id' INT(11) UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
  'first_name' VARCHAR(250) NOT NULL,
  'last_name' VARCHAR(250) NOT NULL,
  'user_name' VARCHAR(50) NOT NULL UNIQUE,
  'email' VARCHAR(250) NOT NULL UNIQUE,
  'password' VARCHAR(250) NOT NULL,
  'last_access' DATETIME DEFAULT NULL,
  'phone' VARCHAR(250) DEFAULT NULL,
  'cellphone' VARCHAR(250) DEFAULT NULL,
  'status' ENUM('Active', 'Inactive', 'Blocked', 'Deleted', 'Newreg') DEFAULT 'Active',
  PRIMARY KEY ('id')
) ENGINE=InnoDB CHARSET=utf8;

MySQL Workbench doesn't show any syntax error, but when executed throws the following error

[2018-03-24 16:07:49] [42000][1064] 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 ''id' INT(11) UNSIGNED AUTO_INCREMENT UNIQUE,
[2018-03-24 16:07:49] 'first_name' VARCHAR(250) NOT NUL' at line 3

'id' is a string, not a variable name. Omit the single quotes:

CREATE TABLE users
(
  id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
  ...
  PRIMARY KEY (id)
)

Or replace them with backticks, like:

CREATE TABLE users
(
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
  ...
  PRIMARY KEY (`id`)
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM