Jump to content

SQL Error...

- - - - -

  • Please log in to reply
5 replies to this topic

#1
isuru

isuru

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 233 posts
Everytime I execute following SQL statements I get error messages.

CREATE TABLE ‘categories’ (

‘id’ INT NOT NULL AUTO_INCREMENT ,

‘name’ VARCHAR( 255 ) NOT NULL ,

‘shortdesc’ VARCHAR( 255 ) NOT NULL ,

‘status’ ENUM( ‘active’, ‘inactive’ ) NOT NULL ,

‘parentid’ INT NOT NULL ,

PRIMARY KEY ( ‘id’ )

) TYPE = MYISAM ;


CREATE TABLE ‘products’ (

‘id’ INT NOT NULL AUTO_INCREMENT ,

‘name’ VARCHAR( 255 ) NOT NULL ,

‘shortdesc’ VARCHAR( 255 ) NOT NULL ,

‘longdesc’ TEXT NOT NULL ,

‘thumbnail’ VARCHAR( 255 ) NOT NULL ,

‘image’ VARCHAR( 255 ) NOT NULL ,

‘grouping’ VARCHAR( 16 ) NOT NULL ,

‘status’ ENUM( ‘active’, ‘inactive’ ) NOT NULL ,

‘category_id’ INT NOT NULL ,

‘featured’ ENUM (‘true’, ‘false’) NOT NULL,

PRIMARY KEY ( ‘id’ )

) TYPE = MYISAM ;


#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 '‘active’, ‘inactive’ ) NOT NULL , ‘category_id’ INT NOT NULL , ‘' at line 9

How do you debug above codes?
Lost!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Based on this: MySQL :: MySQL 5.0 Reference Manual :: 10.4.4 The ENUM Type I think you need to use ' instead of ‘ and ’ for your ENUM string delimiters. It could also be a limitation of TYPE = MYISAM.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
If you have copied the code off a website, or have a non-US character set and keyboard you likely have typed invalid characters.

You must replace each individual singular styled quote for names of tables or columns with the back tick (grave accent) character, which is: `

You must replace your ENUM constant's quotes with a singular quote, which is: '
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
wwarren

wwarren

    Learning Programmer

  • Members
  • PipPipPip
  • 60 posts
Yeah, looks like an encoding problem when you copied and pasted.

For the field names use a back-tick ` and for the values in the ENUM use a single quote '

So It should be like

CREATE TABLE `categories` (

`id` INT NOT NULL AUTO_INCREMENT ,

`name` VARCHAR( 255 ) NOT NULL ,

`shortdesc` VARCHAR( 255 ) NOT NULL ,

`status` ENUM('active', 'inactive') NOT NULL ,

`parentid` INT NOT NULL ,

PRIMARY KEY ( `id` )

) TYPE = MYISAM ;

and

CREATE TABLE `products` (

`id` INT NOT NULL AUTO_INCREMENT ,

`name` VARCHAR( 255 ) NOT NULL ,

`shortdesc` VARCHAR( 255 ) NOT NULL ,

`longdesc` TEXT NOT NULL ,

`thumbnail` VARCHAR( 255 ) NOT NULL ,

`image` VARCHAR( 255 ) NOT NULL ,

`grouping` VARCHAR( 16 ) NOT NULL ,

`status` ENUM( 'active', 'inactive' ) NOT NULL ,

`category_id` INT NOT NULL ,

`featured` ENUM ( 'true', 'false' ) NOT NULL,

PRIMARY KEY ( `id` )

) TYPE = MYISAM ;

Hope this fixes your problem!

#5
isuru

isuru

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 233 posts

wwarren said:

Yeah, looks like an encoding problem when you copied and pasted.

For the field names use a back-tick ` and for the values in the ENUM use a single quote '

So It should be like

CREATE TABLE `categories` (

`id` INT NOT NULL AUTO_INCREMENT ,

`name` VARCHAR( 255 ) NOT NULL ,

`shortdesc` VARCHAR( 255 ) NOT NULL ,

`status` ENUM('active', 'inactive') NOT NULL ,

`parentid` INT NOT NULL ,

PRIMARY KEY ( `id` )

) TYPE = MYISAM ;

and

CREATE TABLE `products` (

`id` INT NOT NULL AUTO_INCREMENT ,

`name` VARCHAR( 255 ) NOT NULL ,

`shortdesc` VARCHAR( 255 ) NOT NULL ,

`longdesc` TEXT NOT NULL ,

`thumbnail` VARCHAR( 255 ) NOT NULL ,

`image` VARCHAR( 255 ) NOT NULL ,

`grouping` VARCHAR( 16 ) NOT NULL ,

`status` ENUM( 'active', 'inactive' ) NOT NULL ,

`category_id` INT NOT NULL ,

`featured` ENUM ( 'true', 'false' ) NOT NULL,

PRIMARY KEY ( `id` )

) TYPE = MYISAM ;

Hope this fixes your problem!


Thanks! This works! Thanks for the help, it was with '.
Lost!

#6
wwarren

wwarren

    Learning Programmer

  • Members
  • PipPipPip
  • 60 posts
No problem :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users