0

I just realized that i assigned a table name as "AS" and when i was trying to do a select query, i kept getting an error:

ERROR 1064 (42000): 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 '"as"'.

So i looked up for reserved words and found out that "AS" is reserved. Well, i think i knew before (used for aliases) but just didn't consider it.

So to fix this will easily be to rename the table name. But assuming i don't want to, can i still access this table using some sort of symbol ? i tried putting it in quotes and double quotes but no success.

  • The 2 answers below are both fine, but I would advise you to change it now if you possibly can. Otherwise you will be having this error every time you touch that table for years! – Kickstart Mar 20 '14 at 13:01

3 Answers3

1

Yes use this(backtiks):

SELECT * FROM `as`
aksu
  • 5,221
  • 5
  • 24
  • 39
1

With mysql, you can wrap reserved words (or any words for that matter) in backticks to cause word to be parsed as a literal name rather than the keyword:

select * from `AS`

Read more about it in the on line documentation under "identifier quote character".

Bohemian
  • 412,405
  • 93
  • 575
  • 722
0

You should use backticks. Else MySQL will consider it as a Keyword. If we use backtick then they are called quoted identifiers and they tell the parser to handle the text between them as a literal string. They are useful for when you have a column or table that contains a keyword or space.

Please refer: http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html

Sathish D
  • 4,854
  • 31
  • 44