views:

287

answers:

7

I am very, very new to MYSQL.I tried to create a table named "option". My SQL Query is :

create table option(

id int not null primary key auto_increment,

choice varchar(30)

)

While executing this query it shows the following error

Error Code : 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 'option( id int not null primary key auto_increment, choice varchar(30) )' at line 1 (0 ms taken)

If I try with the table name as "choice" it is working.

can we have the table name as "option" in mysql?

thanks

+5  A: 

If you want to have a table name Option, you should be able to, just remember that whenever you use the table in a query, you will have to encase it in ` symbols. Like this.

`option`

The ` key on the top left of your keyboard, with the tilde.

Kibbee
It's at the bottom left of my keyboard!
John Topley
+1  A: 

You can use SQL keywords as table names in MySQL if you escape them with back-quotes.

 CREATE TABLE `option` (
     ...
 )

It's not normally a good idea to do so, though.

Alnitak
A: 

option is a reserved word in MySQL. Save yourself a world of pain and use choice for your table name.

John Topley
A: 

See the MySQL documentation on this. You can do it as follows:

create table `option` (
...
)
GalacticCowboy
+8  A: 

Pick a different name (one that isn't a reserved word in your RDBMS) and save yourself and whoever else might work on it many headaches.

Patrick Harrington
While seemingly innocuous to quote, I've been stuck with systems that have tables named 'All' and 'Table' and other reserved words, and one begins to despise the back-tick/bracket.
Thomas G. Mayfield
+4  A: 

option is a reserved word in Mysql.we can use a reserved word by using the word inside a single quotes.

Warrior
+3  A: 

Better you select the other tablename.Ohterwise maintaining our code will be difficult.