MySQL Insert Where query

前端 未结 27 2384
悲&欢浪女
悲&欢浪女 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:57

    The simplest way is to use IF to violate your a key constraint. This only works for INSERT IGNORE but will allow you to use constraint in a INSERT.

    INSERT INTO Test (id, name) VALUES (IF(1!=0,NULL,1),'Test');
    

提交回复
热议问题