10

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

John Topley
  • 113,588
  • 46
  • 195
  • 237
DonX
  • 16,093
  • 21
  • 75
  • 120
  • Per my answer, while you could, you want to get your app / DB off on a good start. Is the single word "option" really the best name for this table? It must be an option for something specific, so spend some time drawing out your data model if you haven't already and the issue should fix itself. – Patrick Harrington Nov 29 '08 at 17:59

8 Answers8

16

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
  • 65,369
  • 27
  • 142
  • 182
11

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
  • 47,416
  • 5
  • 23
  • 20
  • 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. – Tom Mayfield Nov 30 '08 at 03:53
4

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

Warrior
  • 39,156
  • 44
  • 139
  • 214
3

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

2

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
  • 334,560
  • 70
  • 407
  • 495
0

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

John Topley
  • 113,588
  • 46
  • 195
  • 237
0

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

create table `option` (
...
)
GalacticCowboy
  • 11,663
  • 2
  • 41
  • 66
0

Yes you can definitely create a table named option but in every query you will have to use

`option`

instead of plain option. Better improvise a little and create a table named options to save from trouble. Restrain from using mysql reserved words as table name or column name or procedure names.

Ketan Patil
  • 1,222
  • 13
  • 21