1

I have table in MySQL with years as column names like 1960, 1961, 1962... etc. Records are being inserted successfully. When I try to update table with query

UPDATE table1 SET 1960=0.0 WHERE id = 'abc'

it gives:

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 '1960=0.0 WHERE id='abc' at line 1 

Is it due to columns names as numbers or something else is wrong?

1
  • 1
    Thats a very bad choice of naming columns. Anyway, try to surround 1960 with a pair of backtick operator.. Commented Jul 17, 2012 at 14:18

3 Answers 3

3

try this:

UPDATE table1 SET `1960`='0.0' WHERE id = 'abc'

... added backticks to column name and single quotes around value (not really required for the value, but I always do it)

Sign up to request clarification or add additional context in comments.

Comments

3

escape your column name with backticks

UPDATE table1 SET `1960` = 0.0 WHERE id = 'abc'

That has to be done if your column name is a reserved keyword in MySQL or a number.

Comments

0

You'll have to escape your column names by using the backtick character. The following manual page is somewhat dense but informative

Try...

UPDATE table1 SET `1960`=0.0 WHERE id = 'abc'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.