Home  >  Q&A  >  body text

mysql - sql中update语句 and 和直接where语句的区别是什么?

  1. 现在我有如下两条sql请问有什么区别

update customer set moeny = 100 and balance >= 100

udpate customer set money =100 where balance >= 100

PHP中文网PHP中文网2763 days ago646

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 13:49:50

    Let’s talk about the correct way of writing first

    udpate customer set money  =100 where balance >= 100

    All balance >=100 money=100

    Let’s talk about the wrong thing

    update customer set moeny = 100 and balance >= 100

    This error is serious, 会把全局的money变为默认值,通常是0

    The reason is: if there is no where, it is a global set. The multiple setting methods in the set are ','; if and is used, it will be considered as the setting of money, money = (100 and balance >=100), However, the value of this expression is unrecognized and becomes the default value.

    So: the global money becomes the default value, which is very cheating, delete和update千万记得加where,尤其update,因为delete还有提醒.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:49:50

    So that’s it

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 13:49:50

    update customer set moeny = 100 and balance >= 100;
    =>
    update customer set moeny = (100 and balance >= 100);

    That is to say, moeny is all set to 1 or 0.

    reply
    0
  • Cancelreply