Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL server version for the right syntax to use near '('id')

Tags:

mysql

i get this error when i try to inport to data base

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') ) TYPE=MyISAM AUTO_INCREMENT=6' at line 4

 DROP TABLE IF EXISTS `categories`;
 CREATE TABLE `categories` (
 `id` int(5) NOT NULL auto_increment,
  `category` varchar(50) NOT NULL default '',
  PRIMARY KEY  ('id')
  ) TYPE=MyISAM AUTO_INCREMENT=6 ;
like image 224
steve Avatar asked Aug 31 '25 11:08

steve


2 Answers

You are using ' here

PRIMARY KEY  ('id')

id is in this case a string, not the column name. Use backticks instead.

PRIMARY KEY  (`id`)
like image 174
fancyPants Avatar answered Sep 03 '25 14:09

fancyPants


You have two issues with the code, remove the single quotes around the id in the primary key declaration. You can use backticks or nothing.

And change the Type=MyISAM to:

ENGINE=MyISAM

From the MySQL Docs:

The older term TYPE is supported as a synonym for ENGINE for backward compatibility, but ENGINE is the preferred term and TYPE is deprecated.

So the script will be:

DROP TABLE IF EXISTS `categories`;
 CREATE TABLE `categories` (
 `id` int(5) NOT NULL auto_increment,
  `category` varchar(50) NOT NULL default '',
  PRIMARY KEY  (id)
  ) ENGINE=MyISAM AUTO_INCREMENT=6 ;

See SQL Fiddle with Demo

like image 38
Taryn Avatar answered Sep 03 '25 14:09

Taryn