MySQL Insert Where query

前端 未结 27 2167
悲&欢浪女
悲&欢浪女 2020-11-22 06:16

What\'s wrong with this query:

INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 ) WHERE id = 1;

It works without the WHE

27条回答
  •  轮回少年
    2020-11-22 06:59

    Does WHERE-clause can be actually used with INSERT-INTO-VALUES in any case?

    The answer is definitively no.

    Adding a WHERE clause after INSERT INTO ... VALUES ... is just invalid SQL, and will not parse.

    The error returned by MySQL is:

    mysql> INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 ) WHERE id = 1;
    ERROR 1064 (42000): 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 'WHERE id = 1' at line 1
    

    The most important part of the error message is

    ... syntax to use near 'WHERE id = 1' ...
    

    which shows the specific part the parser did not expect to find here: the WHERE clause.

提交回复
热议问题