StackArena

How can I update a table in mysql

1

I have a SQL query UPDATE 'users' SET id='2' WHERE id='12' but i’m getting an error

asked May 1, 2012
canon
5

4 Answers

2
Try this syntax for your query update.

UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value

Although I don't really see anything wrong with the syntax but you can try to remove the quotes from the table name.
1
You don't need to put a quote around your integer value. Try it this way UPDATE 'users' SET id = 2 WHERE id = 12
0
The problem is not with the sql statement. I am guessing the id field you want to update is the primary key and it is an auto_increment column. Which means there should already be an entry with id=2 in your table. That means your SQL statement may not be syntactically wrong but logically wrong and will throw an error of duplicate keys. The best way to get a solution is to paste the error message for us to see.
0
Your Syntax is correct but your logic could be wrong. Am thinking the id is a primary key and as such an auto increment. You probably have an id with the value of 2. Try the update with a different column

Your Answer

Please Log in to continue