开发者

Why I am not able to update the column based on a condition which is not the primary key

Why I am not able to update the column based on a condition which is not the primary key.

I am trying to update the constituencies table where name matches a specific criterial as shown below but the below queries shows an error


Error code 1064, SQL state 42000: You have an error in your SQL syntax; check the manual that correspon开发者_JS百科ds to your MySQL server version for the right syntax to use near 'table constituencies set city_id = '1' where constituencies.name = "East Delhi"' at line 1


update table constituencies set city_id = '1' where constituencies.name = "East Delhi";
update table constituencies set city_id = '1' where constituencies.name = "South Delhi";
update table constituencies set city_id = '1' where constituencies.name = "Delhi Sadar";
update table constituencies set city_id = '1' where constituencies.name = "Karol Bagh";
update table constituencies set city_id = '1' where constituencies.name = "New Delhi";
update table constituencies set city_id = '1' where constituencies.name = "Outer Delhi";
update table constituencies set city_id = '1' where constituencies.name = "North East Delhi";
update table constituencies set city_id = '1' where constituencies.name = "North West Delhi";
update table constituencies set city_id = '1' where constituencies.name = "West Delhi";

Is it necessary that the condition should be checked with a primary key only ?

Please throw some light on the above.


Try

update constituencies set city_id = 1 where constituencies.name = "East Delhi";

You Don't need to write Table in your mysql Query.


You don't need table keyword, as Salil posted. Also, take a look at function IN for your update condition - it could simplify your queries (as you're updating rows with same ID anyways).

Try:

UPDATE constituencies set city_id = '1' 
WHERE name IN 
(
  "East Delhi", "South Delhi", "Delhi Sadar", "Karol Bagh", "New Delhi", 
  "Outer Delhi", "North East Delhi", "North West Delhi", "West Delhi"
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜