Khawar Raza
Khawar Raza

Reputation: 16120

MySQL Update error while updating table

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?

Upvotes: 1

Views: 142

Answers (3)

Andy Jones
Andy Jones

Reputation: 6275

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'

Upvotes: 0

juergen d
juergen d

Reputation: 204924

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.

Upvotes: 3

Brian Adkins
Brian Adkins

Reputation: 666

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)

Upvotes: 3

Related Questions