0

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
Alfre Cano
  • 31
  • 4
  • Possible duplicate of [When to use single quotes, double quotes, and back ticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-back-ticks-in-mysql) – Paul Spiegel Mar 24 '18 at 19:42

1 Answers1

0

'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`)
)
Andomar
  • 232,371
  • 49
  • 380
  • 404