-2

I get the following Mysql error message, when I run it in the Phpmyadmin SQL command.

"Error in query (1064): Syntax error near 'IF NOT EXISTS TABLE 'o2o_category'( 'id' int(11) NOT NULL AUTO_INCREMENT, ' at line 2 "

The sql is below:

CREATE IF NOT EXISTS TABLE 'o2o_category'(
  'id' int(11) NOT NULL AUTO_INCREMENT,
  'name' VARCHAR(50) NOT NULL DEFAULT '',
  'parent_id' int(10)  NOT NULL DEFAULT 0,
  'listorder' int(8) NOT NULL DEFAULT 0,
  'status' tinyint(1) NOT NULL DEFAULT 0,
  'create_time' int(11) NOT NULL DEFAULT 0,
  'update_time' int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY ('id'),
  KEY parent_id('parent_id')
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

Can u give me some clues about what wrong is?

Thanks

Jens
  • 67,715
  • 15
  • 98
  • 113
ed u
  • 19
  • 5
  • 2
    Use backticks around column ans table names not single qoutes – Jens Oct 12 '17 at 05:29
  • why this question was downvoted? this is a valid question. – user1506104 Oct 12 '17 at 05:58
  • 1
    Possible duplicate of [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – Jens Oct 12 '17 at 07:05

1 Answers1

2

It should be CREATE TABLE IF NOT EXISTS and not CREATE IF NOT EXISTS TABLE

CREATE TABLE IF NOT EXISTS `o2o_category`(
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(50) NOT NULL DEFAULT '',
    `parent_id` int(10) NOT NULL DEFAULT 0,
    `listorder` int(8) NOT NULL DEFAULT 0,
    `status` tinyint(1) NOT NULL DEFAULT 0,
    `create_time` int(11) NOT NULL DEFAULT 0,
    `update_time` int(11) NOT NULL DEFAULT 0,
    PRIMARY KEY (`id`),
    KEY parent_id(`parent_id`))ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Carl Binalla
  • 5,393
  • 5
  • 27
  • 46