Neil Yoga Crypto
Neil Yoga Crypto

Reputation: 1035

Create table : Syntax error

CREATE TABLE IF NOT EXISTS 'wp_gom_my_project' (
'my_project_id' int NOT NULL auto_increment,
'my_project_name' text NOT NULL ,
'user_id' int NOT NULL ,
'my_project_description' text NOT NULL ,
'my_project_deadline' datetime NOT NULL ,
PRIMARY KEY  (`my_project_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8

I just can't find the error.

This is the error message:

#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 ''wp_gom_my_project' ( 'my_project_id' int NOT NULL auto_increment, 'my_project' at line 1

Upvotes: 0

Views: 127

Answers (6)

Naveen Kumar Alone
Naveen Kumar Alone

Reputation: 7668

Dont put any quotes, use `

Try this one

Here is reference fiddle or another one with `

CREATE TABLE IF NOT EXISTS wp_gom_my_project (
my_project_id int NOT NULL auto_increment,
my_project_name text NOT NULL ,
user_id int NOT NULL ,
my_project_description text NOT NULL ,
my_project_deadline datetime NOT NULL ,
PRIMARY KEY  (`my_project_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8

Or replace ' with `

Upvotes: 1

Kamil Chaber
Kamil Chaber

Reputation: 578

Use `(back quote) instead of '(apostrophe) when difining column and table names

Upvotes: 0

knittl
knittl

Reputation: 265201

Single quotes denote a string value in MySQL. If you want to quote table names, you have to use a backtick:

CREATE TABLE IF NOT EXISTS `wp_gom_my_project` (
  `my_project_id` int NOT NULL auto_increment,
  `my_project_name` text NOT NULL ,
  `user_id` int NOT NULL ,
  `my_project_description` text NOT NULL ,
  `my_project_deadline` datetime NOT NULL ,
  PRIMARY KEY  (`my_project_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8

Upvotes: 0

Jason OOO
Jason OOO

Reputation: 3552

Table name and column names should not be enclosed with single or double quotes. you can use backticks `

Upvotes: 0

IMSoP
IMSoP

Reputation: 97688

You have the wrong kind of quotes:

  • ' is for quoting strings
  • ` is for quoting identifiers (table names, column names, etc)

Since none of your table or column names would be a keyword anyway, just don't put any quotes at all, and it will look much nicer. :)

Upvotes: 5

Smar
Smar

Reputation: 8591

Table name and other fields should not be quoted.

Try

CREATE TABLE IF NOT EXISTS wp_gom_my_project (
my_project_id int NOT NULL auto_increment,
my_project_name text NOT NULL ,
user_id int NOT NULL ,
my_project_description text NOT NULL ,
my_project_deadline datetime NOT NULL ,
PRIMARY KEY  (`my_project_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8

instead.

Upvotes: 0

Related Questions