So this is my table
-------- -------------- -------------- ------
| I_Code | Name | Category | rate |
-------- -------------- -------------- ------
| 1001 | Masala Dosa | South Indian | 60 |
| 1002 | Vada Sambhar | South Indian | 40 |
| 1003 | Idli | South Indian | 40 |
| 1004 | Chow Mein | Chinese | 80 |
| 2002 | Dimsum | Chinese | 60 |
-------- -------------- -------------- ------
and I_Code is the primary key. I want to change the I_Code of Chow Mein to 2001 and I'm using the following code
use food;
update table items
set I_Code = 2001
where name = "Chow Mein";
But it keeps giving this error
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 'table items set I_Code = 2001 where name = "Chow Mein"' at line 1
What's going wrong and how can I fix this?
CodePudding user response:
Table keyword isn't used after update keyword. Table name will use after update keyword.
update items
set I_Code = 2001
where name = "Chow Mein";
CodePudding user response:
You're syntax is wrong! https://dev.mysql.com/doc/refman/8.0/en/update.html
This should work:
update items
set I_Code = 2001
where name = "Chow Mein";
"update table (tablename)" is not the syntaxt it's just "update (tablename)"
CodePudding user response:
Use the following syntax:
UPDATE table_name SET col-name = value WHERE id = value
Your Answer :
UPDATE items SET I_Code = 2001 WHERE Name = 'Chow Mein';
if this not works , then try this :
SET SQL_SAFE_UPDATES = 0;
UPDATE items SET I_Code = 2001 WHERE Name = 'Chow Mein';
